Commit 268d9e66 authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Change intersection method

parent 5b2b2c74
......@@ -168,7 +168,8 @@ public class FeatureCollisionCheck extends Check{
}
private List<Pair<Polygon,Polygon>> getCollisionPairs(Geometry subjectGeom, Geometry candidateGeom){
List<PolygonIntersection> intersections = getPolygonIntersections(subjectGeom, candidateGeom);
List<PolygonIntersection> intersections = SelfIntersectionUtil
.calculateGeometryIntersections(subjectGeom, candidateGeom, epsilon);
return intersections.stream()
.filter( polySect -> polySect.getType() != PolygonIntersection.IntersectionType.NONE)
.map(polySect -> new Pair<>(polySect.getP1(), polySect.getP2()))
......
......@@ -84,7 +84,37 @@ public class SelfIntersectionUtil {
private SelfIntersectionUtil() {
}
public static List<PolygonIntersection> calculateGeometryIntersections(Geometry subject, Geometry candidate, double delta){
List<TesselatedPolygon> tesselatedSubjectPolygons = tessellateGeometry(subject, delta);
List<TesselatedPolygon> tesselatedCandidatePolygons = tessellateGeometry(candidate, delta);
List<PolygonIntersection> intersections = new ArrayList<>();
for (TesselatedPolygon sPoly : tesselatedSubjectPolygons) {
for (TesselatedPolygon cPoly : tesselatedCandidatePolygons) {
GeometrySelfIntersection intersection = doPolygonsIntersect(sPoly, cPoly, delta);
if (intersection != null) {
intersections.add(PolygonIntersection.triangles(intersection.t1(), intersection.t2()));
}
}
}
return intersections;
}
private static List<TesselatedPolygon> tessellateGeometry(Geometry geom, double delta){
List<TesselatedPolygon> tesselatedPolygons = new ArrayList<>();
for (Polygon p : geom.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);
}
return tesselatedPolygons;
}
public static List<PolygonIntersection> calculateSolidSelfIntersection(Geometry g, double delta) {
List<TesselatedPolygon> tesselatedPolygons = new ArrayList<>();
for (Polygon p : g.getPolygons()) {
......
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