From 8acc9565832f35d76aa7d5785bae3386d1ad1204 Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Mon, 18 Nov 2024 18:51:52 +0100 Subject: [PATCH] Take into account that buildings are areas fixes https://github.com/streetcomplete/StreetComplete/pull/5915#issuecomment-2480734775 --- .../quests/max_height/AddMaxHeight.kt | 2 +- .../util/math/ElementGeometryMath.kt | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/max_height/AddMaxHeight.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/max_height/AddMaxHeight.kt index d288d6335a..60b79cc464 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/max_height/AddMaxHeight.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/max_height/AddMaxHeight.kt @@ -117,7 +117,7 @@ class AddMaxHeight : OsmElementQuestType { // applicable if with any bridge... geometry != null && bridges.any { bridge -> - val bridgeGeometry = mapData.getWayGeometry(bridge.id) as? ElementPolylinesGeometry + val bridgeGeometry = mapData.getWayGeometry(bridge.id) val bridgeLayer = bridge.tags["layer"]?.toIntOrNull() ?: 0 // , that is in a layer above this way diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/math/ElementGeometryMath.kt b/app/src/main/java/de/westnordost/streetcomplete/util/math/ElementGeometryMath.kt index e41d4327d6..af9935b470 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/util/math/ElementGeometryMath.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/util/math/ElementGeometryMath.kt @@ -1,16 +1,31 @@ package de.westnordost.streetcomplete.util.math +import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry +import de.westnordost.streetcomplete.data.osm.geometry.ElementPointGeometry +import de.westnordost.streetcomplete.data.osm.geometry.ElementPolygonsGeometry import de.westnordost.streetcomplete.data.osm.geometry.ElementPolylinesGeometry +import de.westnordost.streetcomplete.data.osm.mapdata.LatLon fun ElementPolylinesGeometry.getOrientationAtCenterLineInDegrees(): Float { val centerLine = polylines.first().centerLineOfPolyline() return centerLine.first.initialBearingTo(centerLine.second).toFloat() } -fun ElementPolylinesGeometry.intersects(other: ElementPolylinesGeometry): Boolean = - getBounds().intersect(other.getBounds()) - && polylines.any { polyline -> - other.polylines.any { otherPolyline -> +fun ElementGeometry.intersects(other: ElementGeometry): Boolean { + // not interested in point geometry here + if (this is ElementPointGeometry || other is ElementPointGeometry) return false + + if (!getBounds().intersect(other.getBounds())) return false + + return asList().any { polyline -> + other.asList().any { otherPolyline -> polyline.intersectsWith(otherPolyline) } } +} + +private fun ElementGeometry.asList(): List> = when (this) { + is ElementPointGeometry -> listOf(listOf(center)) + is ElementPolygonsGeometry -> polygons + is ElementPolylinesGeometry -> polylines +}