Skip to content

Commit

Permalink
Make implementation of note-detection for overlay identical to the on…
Browse files Browse the repository at this point in the history
…e for quest visibility (#5326)
  • Loading branch information
westnordost committed Oct 20, 2023
1 parent bb4a06e commit d0d953d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit d0d953d

Please sign in to comment.