Skip to content

Commit

Permalink
Fix point equality (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Jan 29, 2025
1 parent 11fd6b8 commit 0e161cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,15 @@ public boolean canBePolygon() {
public boolean canBeLine() {
return worldGeometry instanceof Lineal;
}

@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof FromWorld other && other.worldGeometry.equals(worldGeometry));
}

@Override
public int hashCode() {
return worldGeometry.hashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,35 @@ void testGeometryAttributesLine(String expression, double expected) {
any -> assertEquals(expected, (Double) any.getAttrsAtZoom(14).get("attr"), expected / 1e3), 1);
}

@ParameterizedTest
@CsvSource(value = {
"feature.point_along_line(0) == feature.point_along_line(0); true",
"feature.point_along_line(0) == feature.point_along_line(0); true",
"feature.point_along_line(0) == feature.point_along_line(1); true",
"feature.point_along_line(0) == feature.point_along_line(0.5); false",
}, delimiter = ';')
void testGeometryAttributesLineBoolean(String expression, boolean expected) {
var config = """
sources:
osm:
type: osm
url: geofabrik:rhode-island
local_path: data/rhode-island.osm.pbf
layers:
- id: testLayer
features:
- source: osm
attributes:
- key: attr
value: ${%s}
""".formatted(expression);
var sfMatch =
SimpleFeature.createFakeOsmFeature(newLineString(1, 2, 3, 4, 1, 2), Map.of(), "osm", "layer", 1, emptyList(),
new OsmElement.Info(2, 3, 4, 5, "user"));
testFeature(config, sfMatch,
any -> assertEquals(expected, any.getAttrsAtZoom(14).get("attr")), 1);
}

@ParameterizedTest
@CsvSource(value = {
"feature.area('z0 px2'); 1.17743E-10",
Expand Down

0 comments on commit 0e161cd

Please sign in to comment.