Pihentagy
03/16/2023, 10:17 AMJohann Pardanaud
03/16/2023, 10:18 AMval (upper, left) = boundingBox.upperLeft
val (lower, right) = boundingBox.lowerRight
Youssef Shoaib [MOD]
03/16/2023, 10:19 AMcomponent1-4
and have them return the individual BigDecimalsJohann Pardanaud
03/16/2023, 10:19 AMYoussef Shoaib [MOD]
03/16/2023, 10:21 AMdata class BoundingBox(val upperLeft: Coord, val lowerRight: Coord) {
operator fun component1() = upperLeft.lat
operator fun component2() = upperLeft.lng
operator fun component3() = lowerRight.lat
operator fun component4() = lowerRight.lng
}
Edit: this throws an error because component1
and 2 are overloadedPihentagy
03/16/2023, 10:23 AMwbertan
03/16/2023, 10:35 AMdata class NTuple2<T1, T2>(val t1: T1, val t2: T2)
data class NTuple3<T1, T2, T3>(val t1: T1, val t2: T2, val t3: T3)
data class NTuple4<T1, T2, T3, T4>(val t1: T1, val t2: T2, val t3: T3, val t4: T4)
infix fun <T1, T2> T1.then(t2: T2): NTuple2<T1, T2> {
return NTuple2(this, t2)
}
infix fun <T1, T2, T3> NTuple2<T1, T2>.then(t3: T3): NTuple3<T1, T2, T3> {
return NTuple3(this.t1, this.t2, t3)
}
infix fun <T1, T2, T3, T4> NTuple3<T1, T2, T3>.then(t4: T4): NTuple4<T1, T2, T3, T4> {
return NTuple4(this.t1, this.t2, this.t3, t4)
}
And its constructors.
Then you could do something like:
val (upper, left, lower, right) =
boundingBox.upperLeft.lat then
boundingBox.upperLeft.lng then
boundingBox.lowerRight.lat then
boundingBox.lowerRight.lng
🤔 I think it could workphldavies
03/16/2023, 10:47 AMdata class Coord(val latitude: Double, val longitude: Double)
data class Area(val upperLeft: Coord, val lowerRight: Coord)
@JvmInline
value class AreaCoordinates(val area: Area) {
operator fun component1() = area.upperLeft.latitude
operator fun component2() = area.upperLeft.longitude
operator fun component3() = area.lowerRight.latitude
operator fun component4() = area.lowerRight.longitude
}
fun Area.coordinates() = AreaCoordinates(this)
fun main() {
val (a, b, c, d) = Area(Coord(12.34, 56.78), Coord(-56.78, -123.4)).coordinates()
println("$a,$b,$c,$d")
}
Klitos Kyriacou
03/16/2023, 2:30 PMphldavies
03/16/2023, 4:25 PM((a, b), (c, d))