Skip to content

Commit c443791

Browse files
committed
Move coordinate extension method into Coordinate
Signed-off-by: Kyle Corry <[email protected]>
1 parent 76b2727 commit c443791

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

src/main/kotlin/com/kylecorry/sol/science/geography/CoordinateFormatter.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/kotlin/com/kylecorry/sol/units/Coordinate.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import com.kylecorry.sol.math.SolMath.cosDegrees
55
import com.kylecorry.sol.math.SolMath.sinDegrees
66
import com.kylecorry.sol.math.SolMath.toDegrees
77
import com.kylecorry.sol.math.Vector3
8-
import kotlin.math.absoluteValue
9-
import kotlin.math.acos
10-
import kotlin.math.asin
11-
import kotlin.math.atan2
12-
import kotlin.math.cos
13-
import kotlin.math.sin
8+
import com.kylecorry.sol.science.geography.formatting.*
9+
import kotlin.math.*
1410

1511

1612
data class Coordinate(val latitude: Double, val longitude: Double) {
@@ -97,6 +93,23 @@ data class Coordinate(val latitude: Double, val longitude: Double) {
9793
return Coordinate(latitude.coerceIn(-90.0, 90.0), toLongitude(longitude))
9894
}
9995

96+
private val defaultFormats = listOf(
97+
DecimalDegreesCoordinateFormat(),
98+
DegreesDecimalMinutesCoordinateFormat(),
99+
DegreesMinutesSecondsCoordinateFormat(),
100+
UTMCoordinateFormat(),
101+
MGRSCoordinateFormat(),
102+
USNGCoordinateFormat(),
103+
OSGBCoordinateFormat()
104+
)
105+
106+
fun parse(
107+
location: String,
108+
formats: List<CoordinateFormat> = defaultFormats
109+
): Coordinate? {
110+
return formats.firstNotNullOfOrNull { it.parse(location) }
111+
}
112+
100113
internal fun isValidLongitude(longitude: Double): Boolean {
101114
return longitude.absoluteValue <= 180
102115
}

src/test/kotlin/com/kylecorry/sol/science/geography/CoordinateFormatterTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.kylecorry.sol.science.geography
22

3-
import com.kylecorry.sol.science.geography.CoordinateFormatter.parse
43
import com.kylecorry.sol.science.geography.formatting.*
54
import com.kylecorry.sol.units.Bearing
65
import com.kylecorry.sol.units.Coordinate

0 commit comments

Comments
 (0)