-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
174 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
android/src/androidTest/java/com/ivoberger/statikgmaps/android/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
android/src/test/java/com/ivoberger/statikgmaps/android/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/src/main/java/com/ivoberger/statikgmapsapi/core/Location.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.ivoberger.statikgmapsapi.core | ||
|
||
/** | ||
* Container to hold a location either by latitude and longitude or an address | ||
* Latitude and longitude will be checked for validity, addresses won't. | ||
*/ | ||
data class Location( | ||
val latitude: Double? = null, | ||
val longitude: Double? = null, | ||
val address: String? = null | ||
) { | ||
init { | ||
// require coordinates to be set and in their valid ranges or an address to be set | ||
require( | ||
(latitude != null && longitude != null) || address != null | ||
) { "A location must be specified by latitude and longitude or a valid address" } | ||
require( | ||
(latitude != null && longitude != null && latitude in -90.0..90.0 && longitude in -180.0..180.0) | ||
|| address != null | ||
) { "Latitude must be between -90 and 90, longitude between -180 and 180" } | ||
} | ||
|
||
override fun toString() = address ?: "$latitude,$longitude" | ||
} | ||
|
||
|
||
/** | ||
* Creates a [Location] from a [Pair] of [Double] | ||
*/ | ||
fun Pair<Double, Double>.toLocation() = Location(first, second) | ||
|
||
/** | ||
* Creates a [List] of [Location] from a [List] of [Pair] of [Double] | ||
*/ | ||
fun List<Pair<Double, Double>>.toLocations() = map { it.toLocation() } | ||
|
||
|
||
internal fun List<Location>.toUrlParam(): String = fold("") { param, pair -> | ||
"${if (param.isNotBlank()) "$param|" else ""}${pair.latitude},${pair.longitude}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/src/test/kotlin/com/ivoberger/statikgmapsapi/core/PathSimplificationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.ivoberger.statikgmapsapi.core | ||
|
||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class PathSimplificationTest { | ||
|
||
@Test | ||
fun notNecessary() { | ||
val url = StatikGMapsUrl("placeholder") { | ||
size = 300 to 170 | ||
path = listOf( | ||
Location(.0, .0), | ||
Location(.0, 10.0), | ||
Location(5.0, .0), | ||
Location(7.0, .6) | ||
) | ||
} | ||
assertTrue(url.toString().endsWith(url.path.toUrlParam())) | ||
} | ||
|
||
@Test | ||
fun compressionOnly() { | ||
val url = StatikGMapsUrl("placeholder") { | ||
size = 300 to 170 | ||
path = listOf( | ||
Location(.0, .0), | ||
Location(.0, 10.0), | ||
Location(5.0, .0), | ||
Location(7.0, .6) | ||
) | ||
} | ||
assertTrue(url.toString().endsWith(url.path.toUrlParam())) | ||
} | ||
} |