Skip to content

Commit

Permalink
Fixed issue with GeometryUtils.geometrySegmentList not performing nor…
Browse files Browse the repository at this point in the history
…malization on geometry, which breaks compatibility with older versions
  • Loading branch information
smirnovegorv committed Aug 10, 2024
1 parent 0596159 commit 87dbe7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

group 'ru.itmo.idu'
version '3.8.2'
version '3.8.3'

repositories {
maven {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ru/itmo/idu/geometry/GeometryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ public static List<LineSegment> geometrySegmentList(Geometry geometry) {
continue;
}

Geometry normalized = geometry.norm();
if (part instanceof Polygon) {
final Polygon polygonPart = (Polygon) part;
Geometry normalizedPart = part.norm();
if (normalizedPart instanceof Polygon) {
final Polygon polygonPart = (Polygon) normalizedPart;
segmentList.addAll(coordinateSegmentList(polygonPart.getExteriorRing().getCoordinates()));
for (int interiorIdx = 0; interiorIdx < polygonPart.getNumInteriorRing(); ++interiorIdx) {
segmentList.addAll(coordinateSegmentList(polygonPart.getInteriorRingN(interiorIdx).getCoordinates()));
}
} else {
segmentList.addAll(coordinateSegmentList(part.getCoordinates()));
segmentList.addAll(coordinateSegmentList(normalizedPart.getCoordinates()));
}

}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/ru/itmo/idu/geometry/GeometryUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,16 @@ public void testGeometrySegmentList() {
List<LineSegment> polygonWithHoleList = GeometryUtils.geometrySegmentList(polygonWithHole);
Assertions.assertEquals(8, polygonWithHoleList.size());
}

@Test
public void testGeometrySegmentListNormalizes() {
Geometry polygon = GeometryUtils.makePolygon(
new Coordinate(0.0, 0.0),
new Coordinate(1.0, 0.0),
new Coordinate(0.5, 0.5)
);

List<LineSegment> segments = GeometryUtils.geometrySegmentList(polygon);
Assertions.assertEquals(new LineSegment(0.0, 0.0, 0.5, 0.5), segments.get(0));
}
}

0 comments on commit 87dbe7c

Please sign in to comment.