Fix shape using y instead of z coordinates

This commit is contained in:
Lukas Rieger (Blue) 2022-08-02 17:19:38 +02:00
parent 745192e232
commit 1838ebbc93
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
1 changed files with 14 additions and 3 deletions

View File

@ -134,7 +134,7 @@ public final class MarkerGson {
}
static class ShapeAdapter extends TypeAdapter<Shape> {
private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter();
private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter(true);
@Override
public void write(JsonWriter out, Shape value) throws IOException {
@ -217,6 +217,16 @@ public final class MarkerGson {
static class Vector2dAdapter extends TypeAdapter<Vector2d> {
private final boolean useZ;
public Vector2dAdapter() {
this.useZ = false;
}
public Vector2dAdapter(boolean useZ) {
this.useZ = useZ;
}
@Override
public void write(JsonWriter out, Vector2d value) throws IOException {
if (value == null) {
@ -226,7 +236,7 @@ public final class MarkerGson {
out.beginObject();
out.name("x"); out.value(value.getX());
out.name("y"); out.value(value.getY());
out.name(useZ ? "z" : "y"); out.value(value.getY());
out.endObject();
}
@ -242,7 +252,8 @@ public final class MarkerGson {
while (in.peek() != JsonToken.END_OBJECT) {
switch (in.nextName()) {
case "x" : x = in.nextDouble(); break;
case "y" : y = in.nextDouble(); break;
case "y" : if (!useZ) y = in.nextDouble(); else in.skipValue(); break;
case "z" : if (useZ) y = in.nextDouble(); else in.skipValue(); break;
default : in.skipValue(); break;
}
}