mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Add unit test for line_is_too_small
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1551,29 +1551,6 @@ bool find_feature_to_accumulate_onto(std::vector<std::shared_ptr<serial_feature>
|
||||
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.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user