Commit 4b8e8c80 authored by Riegel's avatar Riegel
Browse files

Add function for printing TestCase from false positive

Added a function for the generation of TestCases during debugging for
quicker analysis of false positive self-intersections.
parent 5a4d0a74
...@@ -211,6 +211,83 @@ public class DebugUtils { ...@@ -211,6 +211,83 @@ public class DebugUtils {
return counterArr[0]; return counterArr[0];
} }
public static void printFPSelfIntersectionTestCaseCode(PolygonPolygonIntersection... intersectionResults){
for (PolygonPolygonIntersection intersection : intersectionResults) {
printFPSelfIntersectionTestCaseCode(intersection.getPolygon1(), intersection.getPolygon2());
}
}
public static void printFPSelfIntersectionTestCaseCode(EdgePolygon polygon1, EdgePolygon polygon2) {
Locale.setDefault(Locale.US);
System.out.println("-----------------------------------------------------");
System.out.println("");
System.out.println("@Test");
System.out.println("public void testFalsePositiveCASENAME() {");
printTabbedLine("Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);");
System.out.println("");
printTestCasePolygonCode(polygon1, polygon2);
printTabbedLine("CDPolygonNs edgePoly1 = CDPolygonNs.of(p1, new HashMap<>());");
printTabbedLine("CDPolygonNs edgePoly2 = CDPolygonNs.of(p2, new HashMap<>());");
printTabbedLine("List<PolygonPolygonIntersection> intersectPolygons;");
printTabbedLine("intersectPolygons = IntersectPlanarPolygons.intersectPolygons(edgePoly1, edgePoly2, 0.000001, 0.001);");
printTabbedLine("assertNotNull(intersectPolygons);");
printTabbedLine("assertTrue(intersectPolygons.isEmpty());");
System.out.println("");
printTabbedLine("intersectPolygons = IntersectPlanarPolygons.intersectPolygons(edgePoly2, edgePoly1, 0.000001, 0.001);");
printTabbedLine("assertNotNull(intersectPolygons);");
printTabbedLine("assertTrue(intersectPolygons.isEmpty());");
System.out.println("}");
}
private static void printTabbedLine(String line){
Locale.setDefault(Locale.US);
String format = "\t%s\n";
System.out.format(format, line);
}
private static void printTestCasePolygonCode(EdgePolygon polygon1, EdgePolygon polygon2) {
printTabbedLine("Polygon p1 = new ConcretePolygon();");
printTabbedLine("geom.addPolygon(p1);");
printTabbedLine("LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);");
printTabbedLine("p1.setExteriorRing(ext);");
printTabbedLine("List<Vertex> vertices= new ArrayList<>();");
printTestCasePolygonVertices(polygon1);
System.out.println("");
printTabbedLine("Polygon p2 = new ConcretePolygon();");
printTabbedLine("geom.addPolygon(p2);");
printTabbedLine("ext = new LinearRing(LinearRingType.EXTERIOR);");
printTabbedLine("p2.setExteriorRing(ext);");
printTabbedLine("vertices= new ArrayList<>();");
printTestCasePolygonVertices(polygon2);
System.out.println("");
}
private static void printTestCasePolygonVertices(EdgePolygon polygon) {
List<Coordinate3d> coordList = polygon.getCoordinates();
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(30);
String vertexFormat = "vertices.add(new Vertex(%s,%s,%s));";
for (Coordinate3d coordinate3d : coordList) {
Point3d point = coordinate3d.getPoint();
printTabbedLine(String.format(vertexFormat,
nf.format(point.getX()), nf.format(point.getY()), nf.format(point.getZ())));
}
// close ring
Point3d point = coordList.get(0).getPoint();
printTabbedLine(String.format(vertexFormat,point.getX(),point.getY(),point.getZ()));
printTabbedLine("ext.addAllVertices(vertices);");
}
public static int printCityDoctorPolygons(Polygon... polygons) { public static int printCityDoctorPolygons(Polygon... polygons) {
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
NumberFormat nf = NumberFormat.getNumberInstance(); NumberFormat nf = NumberFormat.getNumberInstance();
......
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