altoslib: Switch preserved state format to JSON
[fw/altos] / altoslib / AltosQuaternion.java
index af9eb47558c701ad273753934826a4f6a5638854..6a09bb8e490d4ef3b36e9b4f9508c7465f1e1bda 100644 (file)
@@ -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);
+       }
 }