Fix AABB type adapters
This commit is contained in:
parent
1f65764310
commit
b0d4a1d0fe
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.11.0
|
projectVersion=2.11.1
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -18,15 +18,17 @@ object AABBTypeAdapter : TypeAdapter<AABB>() {
|
|||||||
|
|
||||||
override fun read(`in`: JsonReader): AABB {
|
override fun read(`in`: JsonReader): AABB {
|
||||||
`in`.beginArray()
|
`in`.beginArray()
|
||||||
val (x1, x2) = Vector2d(`in`.nextDouble(), `in`.nextDouble())
|
val minX = `in`.nextDouble()
|
||||||
val (y1, y2) = Vector2d(`in`.nextDouble(), `in`.nextDouble())
|
val minY = `in`.nextDouble()
|
||||||
|
val maxX = `in`.nextDouble()
|
||||||
|
val maxY = `in`.nextDouble()
|
||||||
`in`.endArray()
|
`in`.endArray()
|
||||||
|
|
||||||
val xMins = x1.coerceAtMost(x2)
|
val xMins = minX.coerceAtMost(maxX)
|
||||||
val xMaxs = x1.coerceAtLeast(x2)
|
val xMaxs = maxX.coerceAtLeast(minX)
|
||||||
|
|
||||||
val yMins = y1.coerceAtMost(y2)
|
val yMins = minY.coerceAtMost(maxY)
|
||||||
val yMaxs = y1.coerceAtLeast(y2)
|
val yMaxs = maxX.coerceAtLeast(minY)
|
||||||
|
|
||||||
return AABB(
|
return AABB(
|
||||||
Vector2d(xMins, yMins),
|
Vector2d(xMins, yMins),
|
||||||
|
@ -18,15 +18,17 @@ object AABBiTypeAdapter : TypeAdapter<AABBi>() {
|
|||||||
|
|
||||||
override fun read(`in`: JsonReader): AABBi {
|
override fun read(`in`: JsonReader): AABBi {
|
||||||
`in`.beginArray()
|
`in`.beginArray()
|
||||||
val (x1, x2) = Vector2i(`in`.nextInt(), `in`.nextInt())
|
val minX = `in`.nextInt()
|
||||||
val (y1, y2) = Vector2i(`in`.nextInt(), `in`.nextInt())
|
val minY = `in`.nextInt()
|
||||||
|
val maxX = `in`.nextInt()
|
||||||
|
val maxY = `in`.nextInt()
|
||||||
`in`.endArray()
|
`in`.endArray()
|
||||||
|
|
||||||
val xMins = x1.coerceAtMost(x2)
|
val xMins = minX.coerceAtMost(maxX)
|
||||||
val xMaxs = x1.coerceAtLeast(x2)
|
val xMaxs = maxX.coerceAtLeast(minX)
|
||||||
|
|
||||||
val yMins = y1.coerceAtMost(y2)
|
val yMins = minY.coerceAtMost(maxY)
|
||||||
val yMaxs = y1.coerceAtLeast(y2)
|
val yMaxs = maxX.coerceAtLeast(minY)
|
||||||
|
|
||||||
return AABBi(
|
return AABBi(
|
||||||
Vector2i(xMins, yMins),
|
Vector2i(xMins, yMins),
|
||||||
|
Loading…
Reference in New Issue
Block a user