Skip to content

Commit

Permalink
Add a line metrics test for a single tile
Browse files Browse the repository at this point in the history
This patch also fixes buffer rounding in `geoJSONToTile()`.

Based on patch from @lbud (Lauren Budorick).
  • Loading branch information
pozdnyakov committed Aug 3, 2018
1 parent 5cc008e commit 1b78d42
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/mapbox/geojsonvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ inline const Tile geoJSONToTile(const geojson& geojson_,
features = detail::wrap(features, double(options.buffer) / options.extent, options.lineMetrics);
}
if (clip || options.lineMetrics) {
const double p = options.buffer / options.extent;
const double p = double(options.buffer) / options.extent;

const auto left = detail::clip<0>(features, (x - p) / z2, (x + 1 + p) / z2, -1, 2, options.lineMetrics);
features = detail::clip<1>(left, (y - p) / z2, (y + 1 + p) / z2, -1, 2, options.lineMetrics);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/single-tile-tiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"geometry":[[[1302,1800],[1302,1734],[1392,1728],[1472,1922],[1487,1915],[1558,1913],[2435,1898],[2553,1866],[3317,1868],[3336,1875],[3343,1885],[3361,1924],[3357,1946],[3382,1935],[3411,1941],[3434,1939],[3460,1926],[3477,1907],[3510,1908],[3954,2108],[4037,2177],[4064,2181],[4081,2177],[4160,2199]]],"type":2,"tags":{"mapbox_clip_start":0,"mapbox_clip_end":0.4210252774113827}}]
27 changes: 27 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,30 @@ TEST(geoJSONToTile, Clips) {
auto name = (props.find("name")->second).get<std::string>();
ASSERT_EQ(name, std::string("District of Columbia"));
}

TEST(geoJSONToTile, Metrics) {
auto geojson = mapbox::geojson::parse(loadFile("test/fixtures/single-tile.json"));
TileOptions options;
options.lineMetrics = true;
options.buffer = 64;
options.tolerance = 3;
const double kEpsilon = 1e-5;

const Tile& tileLeft = mapbox::geojsonvt::geoJSONToTile(geojson, 13, 2342, 3133, options);
ASSERT_EQ(tileLeft.features.size(), 1u);

const Tile& tileRight = mapbox::geojsonvt::geoJSONToTile(geojson, 13, 2343, 3133, options);
ASSERT_EQ(tileRight.features.size(), 1u);

auto& leftProps = tileLeft.features.at(0).properties;
double leftClipStart = (leftProps.find("mapbox_clip_start")->second).get<double>();
EXPECT_DOUBLE_EQ(leftClipStart, 0.0);
double leftClipEnd = (leftProps.find("mapbox_clip_end")->second).get<double>();
EXPECT_NEAR(leftClipEnd, 0.42103, kEpsilon);

auto& rightProps = tileRight.features.at(0).properties;
double rightClipStart = (rightProps.find("mapbox_clip_start")->second).get<double>();
EXPECT_NEAR(rightClipStart, 0.40349, kEpsilon);
double rightClipEnd = (rightProps.find("mapbox_clip_end")->second).get<double>();
EXPECT_DOUBLE_EQ(rightClipEnd, 1.0);
}

0 comments on commit 1b78d42

Please sign in to comment.