From 82e8d96ea6d0aa2fad984a60c55d19bb1af738f2 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Fri, 25 Apr 2025 13:40:49 -0700 Subject: [PATCH] Add unit test for line_is_too_small --- clip.cpp | 23 +++++++++++++++++++++++ geometry.hpp | 1 + tile.cpp | 23 ----------------------- unit.cpp | 9 +++++++++ 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/clip.cpp b/clip.cpp index d4a6f9ce..14ce641a 100644 --- a/clip.cpp +++ b/clip.cpp @@ -2469,3 +2469,26 @@ drawvec fix_polygon(const drawvec &geom, bool use_winding, bool reverse_winding) return out; } + +bool line_is_too_small(drawvec const &geometry, int z, int detail) { + if (geometry.size() == 0) { + return true; + } + + long long x = 0, y = 0; + for (auto &g : geometry) { + if (g.op == VT_MOVETO) { + x = std::llround((double) g.x / (1LL << (32 - detail - z))); + y = std::llround((double) g.y / (1LL << (32 - detail - z))); + } else { + long long xx = std::llround((double) g.x / (1LL << (32 - detail - z))); + long long yy = std::llround((double) g.y / (1LL << (32 - detail - z))); + + if (xx != x || yy != y) { + return false; + } + } + } + + return true; +} diff --git a/geometry.hpp b/geometry.hpp index 73a621ba..4128d8e2 100644 --- a/geometry.hpp +++ b/geometry.hpp @@ -172,5 +172,6 @@ void get_quadkey_bounds(long long xmin, long long ymin, long long xmax, long lon unsigned long long *start, unsigned long long *end); clipbbox parse_clip_poly(std::string arg); +bool line_is_too_small(drawvec const &geometry, int z, int detail); #endif diff --git a/tile.cpp b/tile.cpp index 1049d7fd..bcebbe24 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1551,29 +1551,6 @@ bool find_feature_to_accumulate_onto(std::vector return false; } -static bool line_is_too_small(drawvec const &geometry, int z, int detail) { - if (geometry.size() == 0) { - return true; - } - - long long x = 0, y = 0; - for (auto &g : geometry) { - if (g.op == VT_MOVETO) { - x = std::llround((double) g.x / (1LL << (32 - detail - z))); - y = std::llround((double) g.y / (1LL << (32 - detail - z))); - } else { - long long xx = std::llround((double) g.x / (1LL << (32 - detail - z))); - long long yy = std::llround((double) g.y / (1LL << (32 - detail - z))); - - if (xx != x || yy != y) { - return false; - } - } - } - - return true; -} - // Keep only a sample of 100K extents for feature dropping, // to avoid spending lots of memory on a complete list when there are // hundreds of millions of features. diff --git a/unit.cpp b/unit.cpp index c8f36491..5e0bfa5d 100644 --- a/unit.cpp +++ b/unit.cpp @@ -152,3 +152,12 @@ TEST_CASE("mvt_geometry bbox") { REQUIRE(start == 0x1c84fc0000000000); REQUIRE(end == 0x1c84ffffffffffff); } + +TEST_CASE("line_is_too_small") { + drawvec dv; + dv.emplace_back(VT_MOVETO, 4243099709, 2683872952); + dv.emplace_back(VT_LINETO, 4243102487, 2683873977); + dv.emplace_back(VT_MOVETO, -51867587, 2683872952); + dv.emplace_back(VT_LINETO, -51864809, 2683873977); + REQUIRE(line_is_too_small(dv, 0, 10)); +}