Skip to content

Commit

Permalink
handle negative hash values in ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Feb 19, 2024
1 parent d6471f8 commit a63f15d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.westnordost.streetcomplete.screens.main.map

import android.content.res.Resources
import android.graphics.RectF
import android.util.Log

Check failure on line 5 in app/src/main/java/de/westnordost/streetcomplete/screens/main/map/QuestPinsManager.kt

View workflow job for this annotation

GitHub Actions / Kotlin

Unused import
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import de.westnordost.streetcomplete.data.download.tiles.TilesRect
Expand Down Expand Up @@ -221,8 +222,11 @@ class QuestPinsManager(
val questTypeOrder = questTypeOrders[quest.type] ?: 0
val freeValuesForEachQuest = 100000 / questTypeOrders.size
/* position is used to add values unique to each quest to make ordering consistent
freeValuesForEachQuest is an int, so % freeValuesForEachQuest will fit into int */
val hopefullyUniqueValueForQuest = quest.position.hashCode() % freeValuesForEachQuest
freeValuesForEachQuest is an int, so % freeValuesForEachQuest will fit into int
note that quest.position.hashCode() can be negative and hopefullyUniqueValueForQuest
should be positive to ensure that it will not change quest order
*/
val hopefullyUniqueValueForQuest = (freeValuesForEachQuest + quest.position.hashCode()) % freeValuesForEachQuest
return 100000 - questTypeOrder * freeValuesForEachQuest + hopefullyUniqueValueForQuest
}

Expand Down

0 comments on commit a63f15d

Please sign in to comment.