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 +}