From d0d953de2ed3fc76159a04f84e7171ad1491bec1 Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Fri, 20 Oct 2023 18:51:25 +0200 Subject: [PATCH] Make implementation of note-detection for overlay identical to the one for quest visibility (#5326) --- .../streetcomplete/data/osm/osmquests/OsmQuestController.kt | 6 +----- .../westnordost/streetcomplete/screens/main/MainFragment.kt | 5 ++++- .../java/de/westnordost/streetcomplete/util/ktx/Double.kt | 2 ++ .../java/de/westnordost/streetcomplete/util/ktx/LatLon.kt | 4 ++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt b/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt index 73f3dc5ca3..3b4b3c65f4 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt @@ -26,6 +26,7 @@ import de.westnordost.streetcomplete.util.ktx.format import de.westnordost.streetcomplete.util.ktx.intersects import de.westnordost.streetcomplete.util.ktx.isInAny import de.westnordost.streetcomplete.util.ktx.nowAsEpochMilliseconds +import de.westnordost.streetcomplete.util.ktx.truncateTo5Decimals import de.westnordost.streetcomplete.util.math.contains import de.westnordost.streetcomplete.util.math.enclosingBoundingBox import de.westnordost.streetcomplete.util.math.enlargedBy @@ -421,11 +422,6 @@ class OsmQuestController internal constructor( } } -// the resulting precision is about ~1 meter (see #1089) -private fun LatLon.truncateTo5Decimals() = LatLon(latitude.truncateTo5Decimals(), longitude.truncateTo5Decimals()) - -private fun Double.truncateTo5Decimals() = (this * 1e5).toInt().toDouble() / 1e5 - /** an index by which a list of quest types can be sorted so that quests that are the slowest to * evaluate are evaluated first. This is a performance improvement because the evaluation is done * in parallel on as many threads as there are CPU cores. So if all threads are done except one, diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/main/MainFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/main/MainFragment.kt index b51998ed8f..c434990ed8 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/main/MainFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/main/MainFragment.kt @@ -104,6 +104,7 @@ import de.westnordost.streetcomplete.util.ktx.isLocationEnabled import de.westnordost.streetcomplete.util.ktx.setMargins import de.westnordost.streetcomplete.util.ktx.toLatLon import de.westnordost.streetcomplete.util.ktx.toast +import de.westnordost.streetcomplete.util.ktx.truncateTo5Decimals import de.westnordost.streetcomplete.util.ktx.viewLifecycleScope import de.westnordost.streetcomplete.util.location.FineLocationManager import de.westnordost.streetcomplete.util.location.LocationAvailabilityReceiver @@ -1007,7 +1008,9 @@ class MainFragment : // open note if it is blocking element val center = geometry.center val note = withContext(Dispatchers.IO) { - notesSource.getAll(BoundingBox(center, center).enlargedBy(1.2)).firstOrNull() + notesSource + .getAll(BoundingBox(center, center).enlargedBy(1.2)) + .firstOrNull { it.position.truncateTo5Decimals() == center.truncateTo5Decimals() } } if (note != null) { showQuestDetails(OsmNoteQuest(note.id, note.position)) diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/ktx/Double.kt b/app/src/main/java/de/westnordost/streetcomplete/util/ktx/Double.kt index 7401fa195f..2a203edf5d 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/util/ktx/Double.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/util/ktx/Double.kt @@ -7,3 +7,5 @@ fun Double.toShortString() = if (this % 1 == 0.0) toInt().toString() else toStri fun Double.format(digits: Int) = "%.${digits}f".format(null, this) fun Double.format(locale: Locale, digits: Int) = "%.${digits}f".format(locale, this) + +fun Double.truncateTo5Decimals() = (this * 1e5).toInt().toDouble() / 1e5 diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/ktx/LatLon.kt b/app/src/main/java/de/westnordost/streetcomplete/util/ktx/LatLon.kt index 460ffe5290..4f64921ba5 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/util/ktx/LatLon.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/util/ktx/LatLon.kt @@ -9,3 +9,7 @@ fun LatLon.equalsInOsm(other: LatLon) = && !longitude.isDifferent(other.longitude, 1e-7) private fun Double.isDifferent(other: Double, delta: Double) = abs(this - other) >= delta + +// the resulting precision is about ~1 meter (see #1089): +// earth circumference / 360° / 10^5 => 40075017m / 360 / 100000 = 1.11m +fun LatLon.truncateTo5Decimals() = LatLon(latitude.truncateTo5Decimals(), longitude.truncateTo5Decimals())