Commit 37d7d93f authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Return all intersections of geometries

parent b5a1c606
...@@ -91,10 +91,8 @@ public class SelfIntersectionUtil { ...@@ -91,10 +91,8 @@ public class SelfIntersectionUtil {
List<PolygonIntersection> intersections = new ArrayList<>(); List<PolygonIntersection> intersections = new ArrayList<>();
for (TesselatedPolygon sPoly : tesselatedSubjectPolygons) { for (TesselatedPolygon sPoly : tesselatedSubjectPolygons) {
for (TesselatedPolygon cPoly : tesselatedCandidatePolygons) { for (TesselatedPolygon cPoly : tesselatedCandidatePolygons) {
GeometrySelfIntersection intersection = doPolygonsIntersect(sPoly, cPoly, delta); List<GeometrySelfIntersection> selfInts = doPolygonsIntersect(sPoly, cPoly, delta);
if (intersection != null) { selfInts.forEach(intersection -> intersections.add(PolygonIntersection.triangles(intersection.t1(), intersection.t2())));
intersections.add(PolygonIntersection.triangles(intersection.t1(), intersection.t2()));
}
} }
} }
return intersections; return intersections;
...@@ -116,27 +114,15 @@ public class SelfIntersectionUtil { ...@@ -116,27 +114,15 @@ public class SelfIntersectionUtil {
} }
public static List<PolygonIntersection> calculateSolidSelfIntersection(Geometry g, double delta) { public static List<PolygonIntersection> calculateSolidSelfIntersection(Geometry g, double delta) {
List<TesselatedPolygon> tesselatedPolygons = new ArrayList<>(); List<TesselatedPolygon> tesselatedPolygons = tessellateGeometry(g, delta);
for (Polygon p : g.getPolygons()) {
TesselatedPolygon tessPolygon = EarcutTesselator.tesselatePolygon(p);
for (Iterator<Triangle3d> iterator = tessPolygon.getTriangles().iterator(); iterator.hasNext();) {
Triangle3d t = iterator.next();
if (!t.hasMinExtent(delta)) {
iterator.remove();
}
}
tesselatedPolygons.add(tessPolygon);
}
List<PolygonIntersection> intersections = new ArrayList<>(); List<PolygonIntersection> intersections = new ArrayList<>();
for (int i = 0; i < tesselatedPolygons.size() - 1; i++) { for (int i = 0; i < tesselatedPolygons.size() - 1; i++) {
TesselatedPolygon p1 = tesselatedPolygons.get(i); TesselatedPolygon p1 = tesselatedPolygons.get(i);
for (int j = i + 1; j < tesselatedPolygons.size(); j++) { for (int j = i + 1; j < tesselatedPolygons.size(); j++) {
TesselatedPolygon p2 = tesselatedPolygons.get(j); TesselatedPolygon p2 = tesselatedPolygons.get(j);
GeometrySelfIntersection intersection = doPolygonsIntersect(p1, p2, delta); List<GeometrySelfIntersection> selfInts = doPolygonsIntersect(p1, p2, delta);
if (intersection != null) { selfInts.forEach(intersection -> intersections.add(PolygonIntersection.triangles(intersection.t1(), intersection.t2())));
intersections.add(PolygonIntersection.triangles(intersection.t1(), intersection.t2()));
}
} }
} }
return intersections; return intersections;
...@@ -452,7 +438,7 @@ public class SelfIntersectionUtil { ...@@ -452,7 +438,7 @@ public class SelfIntersectionUtil {
TesselatedPolygon p1 = tessPolys.get(i); TesselatedPolygon p1 = tessPolys.get(i);
for (int j = i + 1; j < tessPolys.size(); j++) { for (int j = i + 1; j < tessPolys.size(); j++) {
TesselatedPolygon p2 = tessPolys.get(j); TesselatedPolygon p2 = tessPolys.get(j);
GeometrySelfIntersection intersection = doPolygonsIntersect(p1, p2, epsilon); GeometrySelfIntersection intersection = doPolygonsIntersect(p1, p2, epsilon).get(0);
if (intersection != null) { if (intersection != null) {
return intersection; return intersection;
} }
...@@ -461,7 +447,8 @@ public class SelfIntersectionUtil { ...@@ -461,7 +447,8 @@ public class SelfIntersectionUtil {
return null; return null;
} }
private static GeometrySelfIntersection doPolygonsIntersect(TesselatedPolygon p1, TesselatedPolygon p2, double epsilon) { private static List<GeometrySelfIntersection> doPolygonsIntersect(TesselatedPolygon p1, TesselatedPolygon p2, double epsilon) {
List<GeometrySelfIntersection> intersections = new ArrayList<>();
for (int p1Index = 0; p1Index < p1.getTriangles().size(); p1Index++) { for (int p1Index = 0; p1Index < p1.getTriangles().size(); p1Index++) {
Triangle3d t1 = p1.getTriangles().get(p1Index); Triangle3d t1 = p1.getTriangles().get(p1Index);
for (int p2Index = 0; p2Index < p2.getTriangles().size(); p2Index++) { for (int p2Index = 0; p2Index < p2.getTriangles().size(); p2Index++) {
...@@ -470,11 +457,11 @@ public class SelfIntersectionUtil { ...@@ -470,11 +457,11 @@ public class SelfIntersectionUtil {
logger.trace("{} intersects {}", t1, t2); logger.trace("{} intersects {}", t1, t2);
logger.trace("GML-ID: {} intersects {}", t1.getPartOf().getOriginal().getGmlId(), logger.trace("GML-ID: {} intersects {}", t1.getPartOf().getOriginal().getGmlId(),
t2.getPartOf().getOriginal().getGmlId()); t2.getPartOf().getOriginal().getGmlId());
return new GeometrySelfIntersection(t1.getPartOf().getOriginal(), t2.getPartOf().getOriginal(), t1, intersections.add( new GeometrySelfIntersection(t1.getPartOf().getOriginal(),
t2); t2.getPartOf().getOriginal(), t1, t2));
} }
} }
} }
return null; return intersections;
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment