Files
tippecanoe/polygon.hpp
T
Claude 91a3ff99f8 With -pn, union spindle strips in the same pass that cleans each polygon
With consistent snapping, each polygon was cleaned with the layer's hot
pixels, but then its spindle strips (if it had any) were unioned with it
in a separate pass, which snapped the whole polygon to tile coordinates a
second time. Snapping already-snapped geometry doesn't necessarily leave it
the same, and the neighbors it shares borders with weren't snapped again to
match. In Dane County tile 12/1027/1502, a narrow water channel's strips
were added where it crossed the edge of the tile's buffer, and that second
pass bent its border with the block next to it, far from the strips,
through the hot pixel at (11, 249), so their edges crossed and overlapped.

So include the rounded strips of every polygon in the layer's hot pixels,
and union each polygon with its strips (with the non-zero fill rule, as
before) in the same wagyu pass that cleans it, so that every polygon is
snapped exactly once, consistently with its neighbors, including where
strips meet other polygons.

For Dane County Census blocks at -D8 -d8 -pt -pn -zg, this reduces the
number of polygons whose overlaps have to be removed afterwards from 2732 to
2482, and the number that are still changing after 4 rounds of overlap
removal from 156 to 14, with still no points covered by more than one
polygon at z8 to z12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
2026-12-01 03:29:02 +00:00

73 lines
3.9 KiB
C++

#ifndef POLYGON_HPP
#define POLYGON_HPP
#include "geometry.hpp"
// One direction of a polygon edge that is shared between two or more
// different polygon features, as identified by --no-simplification-of-shared-nodes,
// in world coordinates. The list of these is sorted by `a` (y, then x)
// and then by `b` (y, then x), and is used to avoid adding spindle strips
// along edges that border other features, where they would overlap them.
struct shared_edge {
long long ax, ay;
long long bx, by;
};
extern shared_edge *shared_edges_map;
extern size_t shared_edges_count;
// Find the parts of a polygon (in world coordinates) that are narrower than
// a pixel at zoom level z with the specified tile detail, and return strips
// (in tile coordinates) covering the pixels along them.
//
// `simplification` is the simplification tolerance, in tile units, that the
// geometry was simplified with, which is how far a simplified shared border
// may have strayed from the original shared edges. (ox, oy) is the world
// coordinate of the tile origin that the geometry is relative to.
drawvec thin_polygon_strips(drawvec const &geom, int z, int detail, double simplification = 1, long long ox = 0, long long oy = 0);
// The length of the ring from geom[i] to geom[j] (world coordinates relative to
// a tile origin at (ox, oy)) that is not made of edges shared with other features
double unshared_perimeter(drawvec const &geom, size_t i, size_t j, long long ox, long long oy);
// Strips (in tile coordinates) one pixel wide along every edge of a polygon
// (in world coordinates relative to a tile origin at (ox, oy)), which together
// trace its outline. This is used to stand in for a polygon that has collapsed
// away to nothing entirely. Edges shared with other features (with
// --no-simplification-of-shared-nodes) are left out, since those features
// already cover the space, and *all_shared is set if every edge was shared.
drawvec outline_strips(drawvec const &geom, int z, int detail, double simplification, long long ox, long long oy, bool *all_shared);
// Hot pixels for snap rounding, as (y, x) in tile coordinates, sorted
typedef std::vector<std::pair<long long, long long>> hot_pixel_list;
// Union the strips from thin_polygon_strips() with a cleaned polygon
// (both in tile coordinates). If `hot` is provided, the result is snapped
// to those hot pixels as in clean_polygon_with_hot_pixels().
drawvec union_polygon_strips(drawvec const &geom, drawvec const &strips, hot_pixel_list const *hot = NULL);
// The hot pixels (vertices and rounded intersections) of all the polygons in
// `geoms` (in tile coordinates), so that each of them can be cleaned with
// clean_polygon_with_hot_pixels() and edges that they share are snapped
// identically in each, instead of differently depending on which other
// vertices each polygon happens to have.
hot_pixel_list layer_hot_pixels(std::vector<drawvec const *> const &geoms);
// Clean a polygon (in tile coordinates), snapping its edges to the hot pixels
// from layer_hot_pixels() as well as its own, and union it with its spindle
// strips (from thin_polygon_strips(), which may be empty) in the same pass,
// so that it is only snapped once. The strips should have been included in
// layer_hot_pixels(). Sets *ok to false if that fails.
drawvec clean_polygon_with_hot_pixels(drawvec const &geom, drawvec const &strips, hot_pixel_list const &hot, bool *ok);
// Polygons (in tile coordinates, in order of priority) that have been cleaned
// with consistent snapping should tile without crossing, but where rounding
// turned a narrow polygon between two others inside out, the area it covered
// may be covered by both of its neighbors. Remove each such overlapping area
// from all but the first of the polygons that cover it. Returns how many
// polygons were changed.
// `hot` is the hot pixels of the layer, from layer_hot_pixels(), if any.
size_t remove_overlaps(std::vector<drawvec *> const &geoms_in, hot_pixel_list const *hot);
#endif