Skip to content

Commit 694ccff

Browse files
committed
Add contains latitude/longitude method for coordinate bounds
Signed-off-by: Kyle Corry <kylecorry31@gmail.com>
1 parent 879f1df commit 694ccff

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id("com.vanniktech.maven.publish") version "0.34.0"
55
}
66

7-
val versionName = "15.4.0"
7+
val versionName = "15.4.1"
88

99
mavenPublishing {
1010
coordinates("com.kylecorry", "sol", versionName)

src/main/kotlin/com/kylecorry/sol/science/geology/CoordinateBounds.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,21 @@ data class CoordinateBounds(val north: Double, val east: Double, val south: Doub
7272
}
7373

7474
override fun contains(location: Coordinate): Boolean {
75-
val containsLatitude = location.latitude in south..north
75+
return containsLatitude(location.latitude) && containsLongitude(location.longitude)
76+
}
77+
78+
fun containsLatitude(latitude: Double): Boolean {
79+
return latitude in south..north
80+
}
7681

77-
val containsLongitude = if (containsAllLongitudes()) {
82+
fun containsLongitude(longitude: Double): Boolean {
83+
return if (containsAllLongitudes()) {
7884
true
7985
} else if (east < 0 && west > 0) {
80-
location.longitude >= west || location.longitude <= east
86+
longitude >= west || longitude <= east
8187
} else {
82-
location.longitude in west..east
88+
longitude in west..east
8389
}
84-
85-
return containsLatitude && containsLongitude
8690
}
8791

8892
fun contains(other: CoordinateBounds): Boolean {
@@ -92,7 +96,7 @@ data class CoordinateBounds(val north: Double, val east: Double, val south: Doub
9296
contains(other.southWest) &&
9397
contains(other.center)
9498
}
95-
99+
96100
fun intersects(other: CoordinateBounds): Boolean {
97101
if (south > other.north || other.south > north) {
98102
return false

0 commit comments

Comments
 (0)