Skip to content

Commit

Permalink
ensure Bounds can be serialized and stored
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Aug 31, 2024
1 parent bf2b992 commit 5822986
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dependencies {
// triangulation algorithm
implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.19.0'

implementation 'com.google.code.gson:gson:2.5'

}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/eu/mihosoft/vrl/v3d/Bounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package eu.mihosoft.vrl.v3d;

import com.google.gson.annotations.Expose;

// TODO: Auto-generated Javadoc
/**
* Bounding box for CSGs.
Expand All @@ -14,21 +16,27 @@
public class Bounds {

/** The center. */
@Expose (serialize = true, deserialize = true)
private final Vector3d center;

/** The bounds. */
@Expose (serialize = true, deserialize = true)
private final Vector3d bounds;

/** The min. */
@Expose (serialize = true, deserialize = true)
private final Vector3d min;

/** The max. */
@Expose (serialize = true, deserialize = true)
private final Vector3d max;

/** The csg. */
@Expose (serialize = false, deserialize = false)
private CSG csg;

/** The cube. */
@Expose (serialize = false, deserialize = false)
private Cube cube;

/**
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/eu/mihosoft/vrl/v3d/Vector3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,32 @@
import static java.lang.Math.min;
import java.util.Random;

import com.google.gson.annotations.Expose;

// TODO: Auto-generated Javadoc
/**
* 3D Vector3d.
*
* @author Michael Hoffer <[email protected]>
*/
public class Vector3d extends javax.vecmath.Vector3d{
public class Vector3d {
/**
* The x coordinate.
*/
@Expose (serialize = true, deserialize = true)
public double x;

/**
* The y coordinate.
*/
@Expose (serialize = true, deserialize = true)
public double y;

/**
* The z coordinate.
*/
@Expose (serialize = true, deserialize = true)
public double z;

/**
*
Expand All @@ -67,7 +85,14 @@ public class Vector3d extends javax.vecmath.Vector3d{

/** The Constant Z_ONE. */
public static final Vector3d Z_ONE = new Vector3d(0, 0, 1);

/**
* Returns the length of this vector.
* @return the length of this vector
*/
public double length()
{
return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
}
/**
* Creates a new vector.
*
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/eu/mihosoft/vrl/v3d/GsonTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eu.mihosoft.vrl.v3d;

import java.lang.reflect.Type;

import org.junit.Test;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class GsonTest {
@Test
public void runGson() {
Type TT_CaDoodleFile = new TypeToken<Bounds>() {
}.getType();
Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation()
.create();
Bounds b = new Cube(100).toCSG().getBounds();
String json = gson.toJson(b);
System.out.println(json);
}
}

0 comments on commit 5822986

Please sign in to comment.