Commit 006bb2b0 authored by Riegel's avatar Riegel
Browse files

Code cleanup

parent 5a615b7c
...@@ -78,21 +78,21 @@ public class PolyLine extends BaseEntity { ...@@ -78,21 +78,21 @@ public class PolyLine extends BaseEntity {
return mpLast; return mpLast;
} }
public Boolean isNullLine() { public boolean isNullLine() {
return isNullLine(0.00); return isNullLine(0.00);
} }
public Boolean isNullLine(Double tolerance) { public boolean isNullLine(double tolerance) {
// If either start or end Segment is null, return immediately // If either start or end Segment is null, return immediately
if (mpFirst == null || mpLast == null) { if (mpFirst == null || mpLast == null) {
return true; return true;
} }
PolyLineSegment currentSegment = mpFirst; PolyLineSegment currentSegment = mpFirst;
Double length = 0.00; double length = 0.00;
// Add length of all segments, starting from mpFirst // Add length of all segments, starting from mpFirst
do { do {
Double segmentLength = currentSegment.getLengthVector().getLength(); double segmentLength = currentSegment.getLengthVector().getLength();
if (segmentLength > tolerance) { if (segmentLength > tolerance) {
length += segmentLength; length += segmentLength;
} }
...@@ -103,15 +103,13 @@ public class PolyLine extends BaseEntity { ...@@ -103,15 +103,13 @@ public class PolyLine extends BaseEntity {
} while (currentSegment.getNext() != null); } while (currentSegment.getNext() != null);
// Since mpLast will be missed due to loop condition add its length afterwards // Since mpLast will be missed due to loop condition add its length afterwards
Double segmentLength = mpLast.getLengthVector().getLength(); double segmentLength = mpLast.getLengthVector().getLength();
if (segmentLength > tolerance) { if (segmentLength > tolerance) {
length += segmentLength; length += segmentLength;
} }
// Check if total length is less than the set tolerance // Check if total length is less than the set tolerance
if (length <= tolerance) { return length <= tolerance;
return true;
}
return false;
} }
......
...@@ -59,8 +59,7 @@ public class PolyLineSegment extends BaseEntity { ...@@ -59,8 +59,7 @@ public class PolyLineSegment extends BaseEntity {
} }
public Vector3d getLengthVector() { public Vector3d getLengthVector() {
Vector3d representation = mpEnd.getPoint().minus(mpStart.getPoint()); return mpEnd.getPoint().minus(mpStart.getPoint());
return representation;
} }
@Override @Override
......
...@@ -21,14 +21,8 @@ package de.hft.stuttgart.citydoctor2.checks.geometry; ...@@ -21,14 +21,8 @@ package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.core.util.internal.Status;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult; import de.hft.stuttgart.citydoctor2.check.CheckResult;
...@@ -84,16 +78,20 @@ public class SolidSelfIntCheckTest { ...@@ -84,16 +78,20 @@ public class SolidSelfIntCheckTest {
assertFalse(m.getBuildings().get(0).containsAnyError()); assertFalse(m.getBuildings().get(0).containsAnyError());
} }
@Test
public void testKnownFalsePositiveExample1() throws CityGmlParseException, InvalidGmlFileException { private void testFalsePositiveExample(String gml_filepath) throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig(); ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
config.setSchematronFilePathInGlobalParameters(null); config.setSchematronFilePathInGlobalParameters(null);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/SolidSelfIntTest-known_false_positive1.gml", config.getParserConfiguration()); CityDoctorModel m = CityGmlParser.parseCityGmlFile(gml_filepath, config.getParserConfiguration());
Checker c = new Checker(config, m); Checker c = new Checker(config, m);
c.runChecks(); c.runChecks();
Building building = m.getBuildings().get(0); Building building = m.getBuildings().get(0);
System.out.println(building.containsAnyError()); System.out.println(building.containsAnyError());
// Example1 Building has some BuildingInstallations, which throw semantic errors /*
* The examples have no actual self-intersections, but can contain other actual model defects.
* If an error is detected, it is thus required to check if the
* False-Positive self-intersection triggered it.
*/
if (building.containsAnyError()) { if (building.containsAnyError()) {
Geometry buildingGeom = building.getGeometry(GeometryType.SOLID, Lod.LOD2); Geometry buildingGeom = building.getGeometry(GeometryType.SOLID, Lod.LOD2);
buildingGeom.clearCheckResults(); buildingGeom.clearCheckResults();
...@@ -101,83 +99,22 @@ public class SolidSelfIntCheckTest { ...@@ -101,83 +99,22 @@ public class SolidSelfIntCheckTest {
check.check(buildingGeom); check.check(buildingGeom);
CheckResult cr = buildingGeom.getCheckResult(check); CheckResult cr = buildingGeom.getCheckResult(check);
assertNotNull(cr); assertNotNull(cr);
//Ensure that checker did not find a self intersection //Ensure that the found error is not a self-intersection error
assertEquals("Known False-Positive self-intersection was detected as error", ResultStatus.OK, cr.getResultStatus()); assertEquals("Known False-Positive self-intersection was detected as error", ResultStatus.OK, cr.getResultStatus());
} }
} }
@Test @Test
public void testKnownFalsePositiveExample2() throws CityGmlParseException, InvalidGmlFileException { public void testKnownFalsePositiveExample1() throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig(); testFalsePositiveExample("src/test/resources/SolidSelfIntTest-known_false_positive1.gml");
config.setSchematronFilePathInGlobalParameters(null);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/SolidSelfIntTest-known_false_positive2.gml", config.getParserConfiguration());
Checker c = new Checker(config, m);
c.runChecks();
Building building = m.getBuildings().get(0);
// If an error was found, check if error is SolidSelfInt
if (building.containsAnyError()) {
Geometry buildingGeom = building.getGeometry(GeometryType.SOLID, Lod.LOD2);
buildingGeom.clearCheckResults();
SolidSelfIntCheck check = new SolidSelfIntCheck();
check.check(buildingGeom);
CheckResult cr = buildingGeom.getCheckResult(check);
assertNotNull(cr);
//Ensure that checker did not find the false-positive self intersection
assertEquals("Known False-Positive self-intersection was detected as error", ResultStatus.OK, cr.getResultStatus());
}
} }
@Ignore("Only run this test locally. The big mesh causes the CI/CD-Runner to crash due to running out of RAM")
@Test @Test
public void testKnownFalsePositiveExample_BigMesh1() throws CityGmlParseException, InvalidGmlFileException { public void testKnownFalsePositiveExample2() throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig(); testFalsePositiveExample("src/test/resources/SolidSelfIntTest-known_false_positive2.gml");
config.setSchematronFilePathInGlobalParameters(null);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/SolidSelfIntTest-known_false_positive_Big_Mesh1.gml", config.getParserConfiguration());
Checker c = new Checker(config, m);
c.runChecks();
Building building = m.getBuildings().get(0);
// If an error was found, check if error is SolidSelfInt
if (building.containsAnyError()) {
Geometry buildingGeom = building.getGeometry(GeometryType.SOLID, Lod.LOD2);
buildingGeom.clearCheckResults();
SolidSelfIntCheck check = new SolidSelfIntCheck();
check.check(buildingGeom);
CheckResult cr = buildingGeom.getCheckResult(check);
assertNotNull(cr);
assertEquals("Known False-Positive self-intersection was detected as error", ResultStatus.OK, cr.getResultStatus());
}
} }
@Ignore("Only run this test locally. The big mesh causes the CI/CD-Runner to crash due to running out of RAM")
@Test
public void testKnownFalsePositiveExample_BigMesh2() throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
config.setSchematronFilePathInGlobalParameters(null);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/SolidSelfIntTest-known_false_positive_Big_Mesh2.gml", config.getParserConfiguration());
Checker c = new Checker(config, m);
c.runChecks();
Building building = m.getBuildings().get(0);
// If an error was found, check if error is SolidSelfInt
if (building.containsAnyError()) {
Geometry buildingGeom = building.getGeometry(GeometryType.SOLID, Lod.LOD2);
buildingGeom.clearCheckResults();
SolidSelfIntCheck check = new SolidSelfIntCheck();
check.check(buildingGeom);
CheckResult cr = buildingGeom.getCheckResult(check);
assertNotNull(cr);
//Ensure that checker did not find the false-positive self intersection
assertEquals("Known False-Positive self-intersection was detected as error", ResultStatus.OK, cr.getResultStatus());
}
}
} }
Markdown is supported
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