add Affine.rotateBox(), min(), max()
[org.ibex.core.git] / src / org / ibex / graphics / Affine.java
index 36cb17f..e5d86b6 100644 (file)
@@ -5,6 +5,7 @@
 // FIXME
 package org.ibex.graphics;
 import java.util.*;
+import org.ibex.util.*;
 
 /** an affine transform; all operations are destructive */
 public final class Affine {
@@ -40,6 +41,20 @@ public final class Affine {
     public boolean equalsIgnoringTranslation(Affine x) { return a == x.a && b == x.b && c == x.c && d == x.d; }
     public Affine clearTranslation() { e = (float)0.0; f = (float)0.0; return this; }
 
+    public long rotateBox(long box) { return rotateBox(Encode.longToFloat1(box), Encode.longToFloat2(box)); }
+    public long rotateBox(float x, float y) {
+        float width = 
+            max(max(multiply_px(0, 0), multiply_px(x, y)), max(multiply_px(x, 0), multiply_px(0, y))) -
+            min(min(multiply_px(0, 0), multiply_px(x, y)), min(multiply_px(x, 0), multiply_px(0, y)));
+        float height = 
+            max(max(multiply_py(0, 0), multiply_py(x, y)), max(multiply_py(x, 0), multiply_py(0, y))) -
+            min(min(multiply_py(0, 0), multiply_py(x, y)), min(multiply_py(x, 0), multiply_py(0, y)));
+        return Encode.twoFloatsToLong(width, height);
+    }
+
+    static float min(float a, float b) { if (a<b) return a; else return b; }
+    static float max(float a, float b) { if (a>b) return a; else return b; }
+
     public boolean equals(Object o) {
         if (!(o instanceof Affine)) return false;
         Affine x = (Affine)o;