JAL-1767 refactoring and tidying of RotatableCanvas and related
[jalview.git] / src / jalview / datamodel / SequencePoint.java
index 28db278..7fcb713 100755 (executable)
@@ -32,9 +32,9 @@ public class SequencePoint
   private final SequenceI sequence;
 
   /*
-   * array of coordinates in embedded sequence space
+   * x, y, z position in 3-D space
    */
-  public float[] coord;
+  public Point coord;
 
   /**
    * Constructor
@@ -42,14 +42,55 @@ public class SequencePoint
    * @param sequence
    * @param coord
    */
-  public SequencePoint(SequenceI sequence, float[] coord)
+  public SequencePoint(SequenceI sequence, Point pt)
   {
     this.sequence = sequence;
-    this.coord = coord;
+    this.coord = pt;
+  }
+
+  /**
+   * Constructor given a sequence and an array of x, y, z coordinate positions
+   * 
+   * @param sequence
+   * @param coords
+   * @throws ArrayIndexOutOfBoundsException
+   *           if array length is less than 3
+   */
+  public SequencePoint(SequenceI sequence, float[] coords)
+  {
+    this(sequence, new Point(coords[0], coords[1], coords[2]));
   }
 
   public SequenceI getSequence()
   {
     return sequence;
   }
+
+  /**
+   * Applies a negative translation of the 'shift' (x, y, z) coordinates
+   * 
+   * @param centre
+   */
+  public void translateBack(Point shift)
+  {
+    float x = coord.x - shift.x;
+    float y = coord.y - shift.y;
+    float z = coord.z - shift.z;
+
+    coord = new Point(x, y, z);
+  }
+
+  /**
+   * Applies a positive translation of the 'shift' (x, y, z) coordinates
+   * 
+   * @param centre
+   */
+  public void translate(Point shift)
+  {
+    float x = coord.x + shift.x;
+    float y = coord.y + shift.y;
+    float z = coord.z + shift.z;
+
+    coord = new Point(x, y, z);
+  }
 }