Commit a28be5d9 authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Simplify util connection visitor

parent e5a1279a
...@@ -91,6 +91,7 @@ public class MisalignedUtilityConnectionCheck extends Check { ...@@ -91,6 +91,7 @@ public class MisalignedUtilityConnectionCheck extends Check {
@Override @Override
public void init(Map<CheckId, Map<String, String>> params, ParserConfiguration config, CityObjectCache cache) { public void init(Map<CheckId, Map<String, String>> params, ParserConfiguration config, CityObjectCache cache) {
Map<String, String> localParameters = params.get(getCheckId()); Map<String, String> localParameters = params.get(getCheckId());
this.cache = cache;
if (localParameters == null) { if (localParameters == null) {
// no parameters // no parameters
return; return;
...@@ -99,7 +100,6 @@ public class MisalignedUtilityConnectionCheck extends Check { ...@@ -99,7 +100,6 @@ public class MisalignedUtilityConnectionCheck extends Check {
if (epsilonString != null) { if (epsilonString != null) {
epsilon = Double.parseDouble(epsilonString); epsilon = Double.parseDouble(epsilonString);
} }
this.cache = cache;
} }
...@@ -140,65 +140,71 @@ public class MisalignedUtilityConnectionCheck extends Check { ...@@ -140,65 +140,71 @@ public class MisalignedUtilityConnectionCheck extends Check {
boolean misalignedConnections = false; boolean misalignedConnections = false;
boolean freeFloating = false; boolean freeFloating = false;
for (Geometry sGeo : subjGeoms) { for (Geometry sGeo : subjGeoms) {
final boolean[] connected = {false}; boolean connected = false;
final boolean[] misalignment = {false}; boolean misalignment = false;
for (CityObject candidate : candidates) { for (CityObject candidate : candidates) {
List<Geometry> candGeoms = new ArrayList<>();
candidate.accept(new CheckableUtilsVisitor() { candidate.accept(new CheckableUtilsVisitor() {
@Override @Override
public void check(Geometry cGeo) { public void check(Geometry cGeo) {
if(sGeo.getLod() != cGeo.getLod()){ if (sGeo.getLod() == cGeo.getLod()) {
return; candGeoms.add(cGeo);
}
List<PolygonIntersection> intersections = SelfIntersectionUtil.calculateGeometryIntersections(sGeo, cGeo, epsilon);
intersections = intersections.stream()
.filter(isect -> isect.getType() != PolygonIntersection.IntersectionType.NONE)
.toList();
for (PolygonIntersection intersection : intersections) {
List<Segment3d> lines = intersection.getLines();
} }
List<Pair<Vertex, Vertex>> pairs = getVertexPairs(sGeo, cGeo); }
if (pairs.size() < 3) { });
if (!pairs.isEmpty()) {
subject.addCheckResult(new CheckResult(CheckId.C_TO_UTILITY_CONNECTION_MISALIGNED,
ResultStatus.ERROR, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignedConnectionError.MisalignmentType.HANGING, ErrorType.ERROR)));
}
} else {
switch(checkConnectionAlignment(sGeo, cGeo, pairs)) {
case ALIGNED:
connected[0] = true;
break;
case ASYMMETRIC_ROTATION:
subject.addCheckResult(new CheckResult(CheckId.C_TO_UTILITY_CONNECTION_MISALIGNED,
ResultStatus.ERROR, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignmentType.ASYMMETRIC_ROTATION, ErrorType.ERROR)));
misalignment[0] = true;
break;
case SHEARED:
subject.addCheckResult(new CheckResult(CheckId.C_TO_UTILITY_CONNECTION_MISALIGNED,
ResultStatus.ERROR, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignmentType.SHEARED, ErrorType.ERROR)));
misalignment[0] = true;
break;
case UNKNOWN:
subject.addCheckResult(new CheckResult(CheckId.C_TO_UTILITY_CONNECTION_MISALIGNED,
ResultStatus.WARNING, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignmentType.UNKNOWN, ErrorType.WARNING)));
misalignment[0] = true;
break;
}
for (Geometry cGeo: candGeoms){
List<PolygonIntersection> intersections = SelfIntersectionUtil.calculateGeometryIntersections(sGeo, cGeo, epsilon);
intersections = intersections.stream()
.filter(isect -> isect.getType() != PolygonIntersection.IntersectionType.NONE)
.toList();
for (PolygonIntersection intersection : intersections) {
List<Segment3d> lines = intersection.getLines();
}
List<Pair<Vertex, Vertex>> pairs = getVertexPairs(sGeo, cGeo);
if (pairs.size() < 3) {
if (!pairs.isEmpty()) {
subject.addCheckResult(new CheckResult(this,
ResultStatus.ERROR, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignedConnectionError.MisalignmentType.HANGING, ErrorType.ERROR)));
}
} else {
ConnectionAlignmentType alignment = checkConnectionAlignment(sGeo, cGeo, pairs);
switch(alignment) {
case ALIGNED:
connected = true;
break;
case ASYMMETRIC_ROTATION:
subject.addCheckResult(new CheckResult(this,
ResultStatus.ERROR, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignmentType.ASYMMETRIC_ROTATION, ErrorType.ERROR)));
misalignment = true;
break;
case SHEARED:
subject.addCheckResult(new CheckResult(this,
ResultStatus.ERROR, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignmentType.SHEARED, ErrorType.ERROR)));
misalignment = true;
break;
case UNKNOWN:
subject.addCheckResult(new CheckResult(this,
ResultStatus.WARNING, new MisalignedConnectionError(sGeo, subject, candidate.getGmlId(),
MisalignmentType.UNKNOWN, ErrorType.WARNING)));
misalignment = true;
break;
} }
} }
}); }
if (!connected[0]) { if (!connected) {
// Geometry has no connections and is "floating in space" // Geometry has no connections and is "floating in space"
freeFloating = true; freeFloating = true;
FloatingUtilityError err = new FloatingUtilityError(subject, sGeo); FloatingUtilityError err = new FloatingUtilityError(subject, sGeo);
subject.addCheckResult(new CheckResult(this, ResultStatus.ERROR, err)); subject.addCheckResult(new CheckResult(this, ResultStatus.ERROR, err));
} else if (misalignment[0]) { } else if (misalignment) {
misalignedConnections = true; misalignedConnections = true;
} }
} }
......
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