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

Code cleanup

parent 5a615b7c
......@@ -78,21 +78,21 @@ public class PolyLine extends BaseEntity {
return mpLast;
}
public Boolean isNullLine() {
public boolean isNullLine() {
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 (mpFirst == null || mpLast == null) {
return true;
}
PolyLineSegment currentSegment = mpFirst;
Double length = 0.00;
double length = 0.00;
// Add length of all segments, starting from mpFirst
do {
Double segmentLength = currentSegment.getLengthVector().getLength();
double segmentLength = currentSegment.getLengthVector().getLength();
if (segmentLength > tolerance) {
length += segmentLength;
}
......@@ -103,15 +103,13 @@ public class PolyLine extends BaseEntity {
} while (currentSegment.getNext() != null);
// 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) {
length += segmentLength;
}
// Check if total length is less than the set tolerance
if (length <= tolerance) {
return true;
}
return false;
return length <= tolerance;
}
......
......@@ -59,8 +59,7 @@ public class PolyLineSegment extends BaseEntity {
}
public Vector3d getLengthVector() {
Vector3d representation = mpEnd.getPoint().minus(mpStart.getPoint());
return representation;
return mpEnd.getPoint().minus(mpStart.getPoint());
}
@Override
......
......@@ -21,14 +21,8 @@ package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.Ignore;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
......@@ -84,39 +78,20 @@ public class SolidSelfIntCheckTest {
assertFalse(m.getBuildings().get(0).containsAnyError());
}
@Test
public void testKnownFalsePositiveExample1() throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
config.setSchematronFilePathInGlobalParameters(null);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/SolidSelfIntTest-known_false_positive1.gml", config.getParserConfiguration());
Checker c = new Checker(config, m);
c.runChecks();
Building building = m.getBuildings().get(0);
System.out.println(building.containsAnyError());
// Example1 Building has some BuildingInstallations, which throw semantic errors
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 a self intersection
assertEquals("Known False-Positive self-intersection was detected as error", ResultStatus.OK, cr.getResultStatus());
}
}
@Test
public void testKnownFalsePositiveExample2() throws CityGmlParseException, InvalidGmlFileException {
private void testFalsePositiveExample(String gml_filepath) throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
config.setSchematronFilePathInGlobalParameters(null);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/SolidSelfIntTest-known_false_positive2.gml", config.getParserConfiguration());
CityDoctorModel m = CityGmlParser.parseCityGmlFile(gml_filepath, 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
System.out.println(building.containsAnyError());
/*
* 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()) {
Geometry buildingGeom = building.getGeometry(GeometryType.SOLID, Lod.LOD2);
buildingGeom.clearCheckResults();
......@@ -124,60 +99,22 @@ public class SolidSelfIntCheckTest {
check.check(buildingGeom);
CheckResult cr = buildingGeom.getCheckResult(check);
assertNotNull(cr);
//Ensure that checker did not find the false-positive 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());
}
}
@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_BigMesh1() throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
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());
}
public void testKnownFalsePositiveExample1() throws CityGmlParseException, InvalidGmlFileException {
testFalsePositiveExample("src/test/resources/SolidSelfIntTest-known_false_positive1.gml");
}
@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());
}
public void testKnownFalsePositiveExample2() throws CityGmlParseException, InvalidGmlFileException {
testFalsePositiveExample("src/test/resources/SolidSelfIntTest-known_false_positive2.gml");
}
}
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