Add missing vector adapters

This commit is contained in:
DBotThePony 2024-03-19 19:00:14 +07:00
parent 83fe5d3ef1
commit b53f2db356
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 115 additions and 1 deletions

View File

@ -4,7 +4,7 @@ kotlin.code.style=official
specifyKotlinAsDependency=false
projectGroup=ru.dbotthepony.kommons
projectVersion=2.9.22
projectVersion=2.9.23
guavaDepVersion=33.0.0
gsonDepVersion=2.8.9

View File

@ -0,0 +1,28 @@
package ru.dbotthepony.kommons.gson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import ru.dbotthepony.kommons.vector.Vector3d
object Vector3dTypeAdapter : TypeAdapter<Vector3d>() {
override fun write(out: JsonWriter, value: Vector3d) {
`out`.beginArray()
`out`.value(value.x)
`out`.value(value.y)
`out`.value(value.z)
`out`.endArray()
}
override fun read(`in`: JsonReader): Vector3d {
`in`.beginArray()
val x = `in`.nextDouble()
val y = `in`.nextDouble()
val z = `in`.nextDouble()
`in`.endArray()
return Vector3d(x, y, z)
}
}

View File

@ -0,0 +1,28 @@
package ru.dbotthepony.kommons.gson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import ru.dbotthepony.kommons.vector.Vector3f
object Vector3fTypeAdapter : TypeAdapter<Vector3f>() {
override fun write(out: JsonWriter, value: Vector3f) {
`out`.beginArray()
`out`.value(value.x)
`out`.value(value.y)
`out`.value(value.z)
`out`.endArray()
}
override fun read(`in`: JsonReader): Vector3f {
`in`.beginArray()
val x = `in`.nextDouble().toFloat()
val y = `in`.nextDouble().toFloat()
val z = `in`.nextDouble().toFloat()
`in`.endArray()
return Vector3f(x, y, z)
}
}

View File

@ -0,0 +1,28 @@
package ru.dbotthepony.kommons.gson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import ru.dbotthepony.kommons.vector.Vector3i
object Vector3iTypeAdapter : TypeAdapter<Vector3i>() {
override fun write(out: JsonWriter, value: Vector3i) {
`out`.beginArray()
`out`.value(value.x)
`out`.value(value.y)
`out`.value(value.z)
`out`.endArray()
}
override fun read(`in`: JsonReader): Vector3i {
`in`.beginArray()
val x = `in`.nextInt()
val y = `in`.nextInt()
val z = `in`.nextInt()
`in`.endArray()
return Vector3i(x, y, z)
}
}

View File

@ -0,0 +1,30 @@
package ru.dbotthepony.kommons.gson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import ru.dbotthepony.kommons.vector.Vector4f
object Vector4fTypeAdapter : TypeAdapter<Vector4f>() {
override fun write(out: JsonWriter, value: Vector4f) {
`out`.beginArray()
`out`.value(value.x)
`out`.value(value.y)
`out`.value(value.z)
`out`.value(value.w)
`out`.endArray()
}
override fun read(`in`: JsonReader): Vector4f {
`in`.beginArray()
val x = `in`.nextDouble().toFloat()
val y = `in`.nextDouble().toFloat()
val z = `in`.nextDouble().toFloat()
val w = `in`.nextDouble().toFloat()
`in`.endArray()
return Vector4f(x, y, z, w)
}
}