Skip to content

Commit

Permalink
AddIsAmenityIndoor: Performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
qugebert committed Sep 17, 2023
1 parent a0d0e45 commit 3a5932f
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.quests.YesNoQuestForm
import de.westnordost.streetcomplete.util.ktx.toYesNo
import de.westnordost.streetcomplete.util.math.LatLonRaster
import de.westnordost.streetcomplete.util.math.contains
import de.westnordost.streetcomplete.util.math.isCompletelyInside
import de.westnordost.streetcomplete.util.math.isInMultipolygon
import java.util.concurrent.FutureTask
Expand Down Expand Up @@ -56,17 +58,22 @@ class AddIsAmenityIndoor(private val featureDictionaryFuture: FutureTask<Feature
it.id to mapData.getGeometry(it.type, it.id) as? ElementPolygonsGeometry
}

val nodesPositions = LatLonRaster(bbox, 0.0005)
for (node in nodes) {
nodesPositions.insert(node.position)
}

buildings.removeAll { building ->
val buildingBounds = buildingGeometriesById[building.id]?.getBounds()
(buildingBounds == null || !buildingBounds.isCompletelyInside(bbox))
(buildingBounds == null || !buildingBounds.isCompletelyInside(bbox) || nodesPositions.getAll(buildingBounds).count() == 0)
}

//Reduce all matching nodes to nodes within building outlines
val nodesInBuildings = nodes.filter {
buildings.any { building ->
val buildingGeometry = buildingGeometriesById[building.id]

if (buildingGeometry != null)
if (buildingGeometry != null && buildingGeometry.getBounds().contains(it.position) )
it.position.isInMultipolygon(buildingGeometry.polygons)
else
false
Expand Down

0 comments on commit 3a5932f

Please sign in to comment.