From a45e561ec27df5de42b212add45e23a90860c291 Mon Sep 17 00:00:00 2001 From: Tobias Knerr Date: Thu, 11 Jul 2024 09:52:07 +0200 Subject: [PATCH] Properly handle building parts with holes in roughlyContains Previously, some building:part multipolygons were not properly associated with the building containing them. --- .../org/osm2world/core/math/GeometryUtil.java | 17 ++++++++++++----- .../core/world/modules/building/Building.java | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/osm2world/core/math/GeometryUtil.java b/src/main/java/org/osm2world/core/math/GeometryUtil.java index 1f9a09ab1..6785b000e 100644 --- a/src/main/java/org/osm2world/core/math/GeometryUtil.java +++ b/src/main/java/org/osm2world/core/math/GeometryUtil.java @@ -2,16 +2,23 @@ import static java.lang.Math.sqrt; import static java.util.Arrays.asList; -import static java.util.Collections.*; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; -import static org.osm2world.core.math.VectorXZ.*; +import static org.osm2world.core.math.VectorXZ.distance; +import static org.osm2world.core.math.VectorXZ.distanceSquared; import static org.osm2world.core.math.algorithms.CAGUtil.subtractPolygons; import java.awt.geom.Line2D; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; import java.util.function.Function; -import org.locationtech.jts.geom.*; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.LineSegment; +import org.osm2world.core.math.shapes.PolygonShapeXZ; import org.osm2world.core.math.shapes.PolylineXZ; import org.osm2world.core.util.color.LColor; @@ -270,7 +277,7 @@ public static final boolean isBetween(VectorXZ p, VectorXZ l1, VectorXZ l2) { * This can be used to prevent small mapping inaccuracies from causing problems, * e.g. when checking if building parts are contained in a building outline. */ - public static final boolean roughlyContains(PolygonWithHolesXZ p1, SimplePolygonXZ p2) { + public static final boolean roughlyContains(PolygonShapeXZ p1, PolygonShapeXZ p2) { if (p1.contains(p2)) { return true; diff --git a/src/main/java/org/osm2world/core/world/modules/building/Building.java b/src/main/java/org/osm2world/core/world/modules/building/Building.java index 29d95f6ef..5565e084c 100644 --- a/src/main/java/org/osm2world/core/world/modules/building/Building.java +++ b/src/main/java/org/osm2world/core/world/modules/building/Building.java @@ -79,7 +79,7 @@ public Building(MapArea area, Configuration config) { return; // belongs to another building's relation } - if (roughlyContains(area.getPolygon(), otherArea.getPolygon().getOuter())) { + if (roughlyContains(area.getPolygon(), otherArea.getPolygon())) { parts.add(new BuildingPart(this, otherArea, config)); }