Skip to content

Commit

Permalink
Properly handle building parts with holes in roughlyContains
Browse files Browse the repository at this point in the history
Previously, some building:part multipolygons were not properly
associated with the building containing them.
  • Loading branch information
tordanik committed Jul 11, 2024
1 parent 1d70476 commit a45e561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/main/java/org/osm2world/core/math/GeometryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit a45e561

Please sign in to comment.