Skip to content

Commit

Permalink
Take into account that buildings are areas
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Nov 18, 2024
1 parent 147cb25 commit 8acc956
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AddMaxHeight : OsmElementQuestType<MaxHeightAnswer> {

// 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<LatLon>> = when (this) {
is ElementPointGeometry -> listOf(listOf(center))
is ElementPolygonsGeometry -> polygons
is ElementPolylinesGeometry -> polylines
}

0 comments on commit 8acc956

Please sign in to comment.