summaryrefslogtreecommitdiff
path: root/altoslib/AltosQuaternion.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-06-15 22:40:27 -0700
committerKeith Packard <keithp@keithp.com>2016-06-15 22:40:27 -0700
commit1b5ea911049a8afae6af475a4a2bf62a6e3aa57b (patch)
tree7f896e587da5e7911b7b5a42aade1b7692670200 /altoslib/AltosQuaternion.java
parent1de8b6c340cec0b5a327392686c5a4e00f201e98 (diff)
altoslib: Switch preserved state format to JSON
This is much easier to debug than the icky strings with backslashes everywhere. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosQuaternion.java')
-rw-r--r--altoslib/AltosQuaternion.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/altoslib/AltosQuaternion.java b/altoslib/AltosQuaternion.java
index af9eb475..6a09bb8e 100644
--- a/altoslib/AltosQuaternion.java
+++ b/altoslib/AltosQuaternion.java
@@ -17,7 +17,7 @@
package org.altusmetrum.altoslib_11;
-public class AltosQuaternion implements AltosHashable {
+public class AltosQuaternion implements AltosHashable, AltosJsonable {
double r; /* real bit */
double x, y, z; /* imaginary bits */
@@ -158,6 +158,16 @@ public class AltosQuaternion implements AltosHashable {
return h;
}
+ public AltosJson json() {
+ AltosJson j = new AltosJson();
+
+ j.put("r", r);
+ j.put("x", x);
+ j.put("y", y);
+ j.put("z", z);
+ return j;
+ }
+
public AltosQuaternion(AltosHashSet h) {
if (h == null)
return;
@@ -167,4 +177,14 @@ public class AltosQuaternion implements AltosHashable {
y = h.getDouble("y", 0);
z = h.getDouble("z", 0);
}
+
+ public AltosQuaternion(AltosJson j) {
+ if (j == null)
+ return;
+
+ r = j.get_double("r", 1);
+ x = j.get_double("x", 0);
+ y = j.get_double("y", 0);
+ z = j.get_double("z", 0);
+ }
}