mirror of
https://github.com/felt/tippecanoe.git
synced 2026-12-05 06:41:41 +01:00
The previous change, which stopped wagyu from snapping an edge to a hot pixel whose corner it only touches, made two of upstream wagyu's 3320 geometry fixtures produce spikes. When an intersection lies exactly on a pixel corner, it is rounded to that pixel, and the edges that intersect there must be snapped to it; and once an edge has been snapped to one hot pixel, its new segments may pass through the interior of another hot pixel whose corner the original edge only touched. So now the inward rounding of the hot pixel range only applies to an edge that intersects no other edge (which is recorded while the hot pixels are built), and never to a hot pixel that is the rounded location of an intersection (which are now kept in a separate sorted list). Edges that are part of intersections are snapped exactly as before. With this, upstream wagyu's unit tests and all 3320 of its geometry fixtures pass, and the narrow diagonal Census block in Dane County is still preserved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
127 lines
3.7 KiB
C++
127 lines
3.7 KiB
C++
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include <list>
|
|
|
|
#include <mapbox/geometry/point.hpp>
|
|
#include <mapbox/geometry/wagyu/config.hpp>
|
|
#include <mapbox/geometry/wagyu/util.hpp>
|
|
|
|
#ifdef DEBUG
|
|
#include <iostream>
|
|
#endif
|
|
|
|
namespace mapbox {
|
|
namespace geometry {
|
|
namespace wagyu {
|
|
|
|
template <typename T>
|
|
struct bound;
|
|
|
|
template <typename T>
|
|
using bound_ptr = bound<T>*;
|
|
|
|
template <typename T>
|
|
struct edge {
|
|
mapbox::geometry::point<T> bot;
|
|
mapbox::geometry::point<T> top;
|
|
double dx;
|
|
// Whether this edge intersects any other edge, which is found while
|
|
// building the hot pixels. An edge that does not intersect any other
|
|
// edge is not snapped to hot pixels whose corners it only touches.
|
|
bool intersected = false;
|
|
|
|
edge(edge<T>&& e) noexcept
|
|
: bot(std::move(e.bot)), top(std::move(e.top)), dx(std::move(e.dx)), intersected(e.intersected) {
|
|
}
|
|
|
|
edge& operator=(edge<T>&& e) noexcept {
|
|
bot = std::move(e.bot);
|
|
top = std::move(e.top);
|
|
dx = std::move(e.dx);
|
|
intersected = e.intersected;
|
|
return *this;
|
|
}
|
|
|
|
template <typename T2>
|
|
edge(mapbox::geometry::point<T2> const& current, mapbox::geometry::point<T2> const& next_pt) noexcept
|
|
: bot(static_cast<T>(current.x), static_cast<T>(current.y)),
|
|
top(static_cast<T>(current.x), static_cast<T>(current.y)),
|
|
dx(0.0) {
|
|
if (current.y >= next_pt.y) {
|
|
top = mapbox::geometry::point<T>(static_cast<T>(next_pt.x), static_cast<T>(next_pt.y));
|
|
} else {
|
|
bot = mapbox::geometry::point<T>(static_cast<T>(next_pt.x), static_cast<T>(next_pt.y));
|
|
}
|
|
double dy = static_cast<double>(top.y - bot.y);
|
|
if (value_is_zero(dy)) {
|
|
dx = std::numeric_limits<double>::infinity();
|
|
} else {
|
|
dx = static_cast<double>(top.x - bot.x) / dy;
|
|
}
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
using edge_ptr = edge<T>*;
|
|
|
|
template <typename T>
|
|
using edge_list = std::vector<edge<T>>;
|
|
|
|
template <typename T>
|
|
using edge_list_itr = typename edge_list<T>::iterator;
|
|
|
|
template <typename T>
|
|
bool slopes_equal(edge<T> const& e1, edge<T> const& e2) {
|
|
return static_cast<std::int64_t>(e1.top.y - e1.bot.y) * static_cast<std::int64_t>(e2.top.x - e2.bot.x) ==
|
|
static_cast<std::int64_t>(e1.top.x - e1.bot.x) * static_cast<std::int64_t>(e2.top.y - e2.bot.y);
|
|
}
|
|
|
|
template <typename T>
|
|
inline bool is_horizontal(edge<T> const& e) {
|
|
return std::isinf(e.dx);
|
|
}
|
|
|
|
template <typename T>
|
|
inline double get_current_x(edge<T> const& edge, const T current_y) {
|
|
if (current_y == edge.top.y) {
|
|
return static_cast<double>(edge.top.x);
|
|
} else {
|
|
return static_cast<double>(edge.bot.x) + edge.dx * static_cast<double>(current_y - edge.bot.y);
|
|
}
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
template <class charT, class traits, typename T>
|
|
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out, const edge<T>& e) {
|
|
out << " Edge: " << std::endl;
|
|
out << " bot x: " << e.bot.x << " y: " << e.bot.y << std::endl;
|
|
out << " top x: " << e.top.x << " y: " << e.top.y << std::endl;
|
|
return out;
|
|
}
|
|
|
|
template <class charT, class traits, typename T>
|
|
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
|
|
edge_list<T> const& edges) {
|
|
out << "[";
|
|
bool first = true;
|
|
for (auto const& e : edges) {
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
out << ",";
|
|
}
|
|
out << "[[" << e.bot.x << "," << e.bot.y << "],[";
|
|
out << e.top.x << "," << e.top.y << "]]";
|
|
}
|
|
out << "]";
|
|
return out;
|
|
}
|
|
|
|
#endif
|
|
} // namespace wagyu
|
|
} // namespace geometry
|
|
} // namespace mapbox
|