CRUCIAL bug fix to Affine.java
authoradam <adam@megacz.com>
Sun, 26 Jun 2005 06:49:29 +0000 (06:49 +0000)
committeradam <adam@megacz.com>
Sun, 26 Jun 2005 06:49:29 +0000 (06:49 +0000)
darcs-hash:20050626064929-5007d-0470b82469a5873d85bf4b62ca4d48a0b68776a9.gz

src/org/ibex/graphics/Affine.java

index 0956adc..df9208b 100644 (file)
@@ -9,8 +9,8 @@ import java.util.*;
 /** an affine transform; all operations are destructive */
 public final class Affine {
 
 /** an affine transform; all operations are destructive */
 public final class Affine {
 
-    //  [ a b e ]
-    //  [ c d f ]
+    //  [ a c e ]
+    //  [ b d f ]
     //  [ 0 0 1 ]
     public float a, b, c, d, e, f;
 
     //  [ 0 0 1 ]
     public float a, b, c, d, e, f;
 
@@ -52,8 +52,8 @@ public final class Affine {
         return new Affine(c, s, -s, c, 0, 0);
     }
 
         return new Affine(c, s, -s, c, 0, 0);
     }
 
-    /** this = this * a */
-    public Affine multiply(Affine A) {
+    /** this = a * this */
+    public Affine premultiply(Affine A) {
         float _a = this.a * A.a + this.b * A.c;
         float _b = this.a * A.b + this.b * A.d;
         float _c = this.c * A.a + this.d * A.c;
         float _a = this.a * A.a + this.b * A.c;
         float _b = this.a * A.b + this.b * A.d;
         float _c = this.c * A.a + this.d * A.c;
@@ -64,8 +64,8 @@ public final class Affine {
         return this;
     }
 
         return this;
     }
 
-    /** this = a * this */
-    public Affine premultiply(Affine A) {
+    /** this = this * a */
+    public Affine multiply(Affine A) {
         float _a = A.a * this.a + A.b * this.c;
         float _b = A.a * this.b + A.b * this.d;
         float _c = A.c * this.a + A.d * this.c;
         float _a = A.a * this.a + A.b * this.c;
         float _b = A.a * this.b + A.b * this.d;
         float _c = A.c * this.a + A.d * this.c;
@@ -77,13 +77,13 @@ public final class Affine {
     }
 
     public Affine invert() {
     }
 
     public Affine invert() {
-        float det = 1 / (a * d - b * c);
-        float _a = d * det;
-        float _b = -1 * b * det;
-        float _c = -1 * c * det;
-        float _d = a * det;
-        float _e = -1 * e * a - f * c;
-        float _f = -1 * e * b - f * d;
+        float det = (a * d - b * c);
+        float _a = d / det;
+        float _b = -1 * b / det;
+        float _c = -1 * c / det;
+        float _d = a / det;
+        float _e = (f*c-e*d)/det;
+        float _f = (b*e-a*f)/det;
         a = _a; b = _b; c = _c; d = _d; e = _e; f = _f;
         return this;
     }
         a = _a; b = _b; c = _c; d = _d; e = _e; f = _f;
         return this;
     }