Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce marker coordinate precision #5

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/main/java/de/bluecolored/bluemap/api/gson/MarkerGson.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ public void write(JsonWriter out, Vector2d value) throws IOException {
}

out.beginObject();
out.name("x"); out.value(value.getX());
out.name(useZ ? "z" : "y"); out.value(value.getY());
out.name("x"); writeRounded(out, value.getX());
out.name(useZ ? "z" : "y"); writeRounded(out, value.getY());
out.endObject();
}

Expand All @@ -262,6 +262,13 @@ public Vector2d read(JsonReader in) throws IOException {
return new Vector2d(x, y);
}

private void writeRounded(JsonWriter json, double value) throws IOException {
// rounding and remove ".0" to save string space
double d = Math.round(value * 10000d) / 10000d;
if (d == (long) d) json.value((long) d);
else json.value(d);
}

}

static class Vector3dAdapter extends TypeAdapter<Vector3d> {
Expand All @@ -274,9 +281,9 @@ public void write(JsonWriter out, Vector3d value) throws IOException {
}

out.beginObject();
out.name("x"); out.value(value.getX());
out.name("y"); out.value(value.getY());
out.name("z"); out.value(value.getZ());
out.name("x"); writeRounded(out, value.getX());
out.name("y"); writeRounded(out, value.getY());
out.name("z"); writeRounded(out, value.getZ());
out.endObject();
}

Expand All @@ -302,6 +309,13 @@ public Vector3d read(JsonReader in) throws IOException {
return new Vector3d(x, y, z);
}

private void writeRounded(JsonWriter json, double value) throws IOException {
// rounding and remove ".0" to save string space
double d = Math.round(value * 10000d) / 10000d;
if (d == (long) d) json.value((long) d);
else json.value(d);
}

}

static class Vector2iAdapter extends TypeAdapter<Vector2i> {
Expand Down