Skip to content

Commit a6af107

Browse files
committed
Fix invalid center point of BoundingBoxE6.NULL_BOX
1 parent 65812fc commit a6af107

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

aat-lib/src/main/java/ch/bailu/aat_lib/coordinates/BoundingBoxE6.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ class BoundingBoxE6 {
141141
val longitudeSpanE6: Int
142142
get() = abs(lonWestE6 - lonEastE6)
143143
val center: LatLongE6
144-
get() = LatLongE6(latSouthE6 + latitudeSpanE6 / 2, lonWestE6 + longitudeSpanE6 / 2)
144+
get() {
145+
val la = validate(latSouthE6 + latitudeSpanE6 / 2, MIN_LA, MAX_LA)
146+
val lo = validate(lonWestE6 + longitudeSpanE6 / 2, MIN_LO, MAX_LO)
147+
return LatLongE6(la, lo)
148+
}
145149

146150
private fun validate() {
147151
latNorthE6 = validate(latNorthE6, MIN_LA, MAX_LA)

aat-lib/src/main/java/ch/bailu/aat_lib/service/directory/GpxInformationDbSummary.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ class GpxInformationDbSummary(private val directory: Foc, cursor: DbResultSet) :
3838
}
3939

4040
private fun addEntryToList(entry: GpxInformation) {
41-
val point = GpxPoint(
42-
entry.getBoundingBox().center,
43-
0f, entry.getTimeStamp()
44-
)
45-
41+
val point = GpxPoint(entry.getBoundingBox().center, 0f, entry.getTimeStamp())
4642
list.appendToCurrentSegment(point, GpxAttributesNull.NULL)
4743
maxSpeed.add(entry.getSpeed())
4844
}

aat-lib/src/test/kotlin/ch/bailu/aat_lib/coordinates/BoundingE6Test.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,19 @@ class BoundingE6Test {
2020
fun nullBounding() {
2121
val boundingBoxE6 = BoundingBoxE6.NULL_BOX
2222
assertEquals(false, boundingBoxE6.hasBounding())
23+
24+
val center = boundingBoxE6.center
25+
val boundingBox = boundingBoxE6.toBoundingBox()
26+
val center1 = boundingBox.centerPoint
27+
assertEquals(0, center1.latitudeE6)
28+
assertEquals(0, center1.longitudeE6)
29+
assertEquals(0.0, center1.latitude)
30+
assertEquals(0.0, center1.longitude)
31+
32+
val center2 = center.toLatLong()
33+
assertEquals(90000000, center2.latitudeE6)
34+
assertEquals(180000000, center2.longitudeE6)
35+
assertEquals(90.0, center2.latitude)
36+
assertEquals(180.0, center2.longitude)
2337
}
2438
}

0 commit comments

Comments
 (0)