Skip to content

Commit

Permalink
use multiples of 5 for data area
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Jan 26, 2025
1 parent 7a96d7b commit b971330
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
applicationId "org.blitzortung.android.app"
minSdkVersion 21
targetSdkVersion 34
versionCode 330
versionCode 331
versionName '2.3.0'
multiDexEnabled false
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.blitzortung.android.data.beans.GridParameters
import org.osmdroid.util.BoundingBox
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.round

Expand Down Expand Up @@ -56,11 +57,7 @@ class LocalData @Inject constructor() {
}

fun update(boundingBox: BoundingBox, force: Boolean = false): Boolean {
val dataArea =
max(
MIN_DATA_AREA,
round(DATA_AREA_SCALING * max(boundingBox.longitudeSpanWithDateLine, boundingBox.latitudeSpan)).toInt()
)
val dataArea = calculateDataArea(boundingBox)
val xPos = calculateLocalCoordinate(boundingBox.centerLongitude, dataArea)
val yPos = calculateLocalCoordinate(boundingBox.centerLatitude, dataArea)
val localReference = LocalReference(xPos, yPos)
Expand Down Expand Up @@ -89,6 +86,12 @@ class LocalData @Inject constructor() {
}
}

private fun calculateDataArea(boundingBox: BoundingBox): Int {
val maxExtent = max(boundingBox.longitudeSpanWithDateLine, boundingBox.latitudeSpan)
val targetValue = DATA_AREA_SCALING * maxExtent
return (ceil(targetValue / MIN_DATA_AREA) * MIN_DATA_AREA).toInt()
}

private fun isOutside(boundingBox: BoundingBox, gridParameters: GridParameters): Boolean {
return boundingBox.lonWest < gridParameters.longitudeStart ||
boundingBox.lonEast > gridParameters.longitudeEnd ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ class LocalDataTest {
val result = uut.update(boundingBox2)

assertThat(result).isTrue
assertThat(uut.dataArea).isEqualTo(6)
assertThat(uut.localReference).isEqualTo(LocalReference(1, 7))
assertThat(uut.dataArea).isEqualTo(10)
assertThat(uut.localReference).isEqualTo(LocalReference(1, 4))
}

fun createLocation(x: Double, y: Double): Location {
Expand Down

0 comments on commit b971330

Please sign in to comment.