Skip to content

Commit

Permalink
test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Feb 3, 2025
1 parent 91ce1f5 commit f1791b9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public Map<String, List<VectorTile.Feature>> postProcessTile(TileCoord tile,
e.log(stats, "clip", "Failed to clip geometry");
}
}
output.put(layer.getKey(), clippedFeatures);
if (!clippedFeatures.isEmpty())
output.put(layer.getKey(), clippedFeatures);
}
return output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,31 @@ void testClipPolygon() throws GeometryException {
assertEquals(newPolygon(64, 160, 96, 160, 96, 192, 64, 192, 64, 160),
clipped.get("layer").getFirst().geometry().decode());
}

@Test
void testClipBelowMinZoom() throws GeometryException {
List<VectorTile.Feature> unclipped = new ArrayList<>();
unclipped.add(new VectorTile.Feature("layer", 1,
VectorTile.encodeGeometry(newLineString(0, 128, 256, 128)),
Map.of("foo", "bar")
));

var n = new Clip(stats, 1, 1, newPolygon(0.25, 0.25, 0.75, 0.25, 0.75, 0.75, 0.25, 0.75, 0.25, 0.25));
var clipped = n.postProcessTile(TileCoord.ofXYZ(0, 0, 0), Map.of("layer", unclipped));
assertEquals(0, clipped.size());
}

@Test
void testClipWhollyOutside() throws GeometryException {
List<VectorTile.Feature> unclipped = new ArrayList<>();
unclipped.add(new VectorTile.Feature("layer", 1,
VectorTile.encodeGeometry(newLineString(0, 1, 5, 1)),
Map.of("foo", "bar")
));

var n = new Clip(stats, 0, 0, newPolygon(0.25, 0.25, 0.75, 0.25, 0.75, 0.75, 0.25, 0.75, 0.25, 0.25));
var clipped = n.postProcessTile(TileCoord.ofXYZ(0, 0, 0), Map.of("layer", unclipped));
System.out.println(clipped);
assertEquals(0, clipped.size());
}
}

0 comments on commit f1791b9

Please sign in to comment.