2003/10/07 20:37:25
[org.ibex.core.git] / src / org / xwt / VectorGraphics.java
index e028caa..55c0930 100644 (file)
@@ -78,6 +78,13 @@ public final class VectorGraphics {
        public static Affine flip(boolean horiz, boolean vert) { return new Affine(horiz ? -1 : 1, 0, 0, vert ? -1 : 1, 0, 0); }
         public float multiply_px(float x, float y) { return x * a + y * c + e; }
        public float multiply_py(float x, float y) { return x * b + y * d + f; }
+        public boolean equalsIgnoringTranslation(Affine x) { return a == x.a && b == x.b && c == x.c && d == x.d; }
+
+        public boolean equals(Object o) {
+            if (!(o instanceof Affine)) return false;
+            Affine x = (Affine)o;
+            return a == x.a && b == x.b && c == x.c && d == x.d && e == x.e && f == x.f;
+        }
 
        public static Affine rotate(float degrees) {
            float s = (float)Math.sin(degrees * (float)(Math.PI / 180.0));
@@ -191,20 +198,6 @@ public final class VectorGraphics {
        static final byte TYPE_CUBIC = 3;
        static final byte TYPE_QUADRADIC = 4;
 
-        // FEATURE: make this faster and cache it; also deal with negative coordinates
-        public int boundingBoxWidth() {
-            int ret = 0;
-            for(int i=0; i<numvertices; i++) ret = Math.max(ret, (int)Math.ceil(x[i]));
-            return ret;
-        }
-
-        // FEATURE: make this faster and cache it; also deal with negative coordinates
-        public int boundingBoxHeight() {
-            int ret = 0;
-            for(int i=0; i<numvertices; i++) ret = Math.max(ret, (int)Math.ceil(y[i]));
-            return ret;
-        }
-
         /** Creates a concrete vector path transformed through the given matrix. */
        public RasterPath realize(Affine a) {
 
@@ -485,6 +478,9 @@ public final class VectorGraphics {
        int[] edges = new int[DEFAULT_PATHLEN];
         int numedges = 0;
 
+        /** translate a rasterized path */
+        public void translate(int dx, int dy) { for(int i=0; i<numvertices; i++) { x[i] += dx; y[i] += dy; } }
+
         /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */
         int sort(int left, int right, boolean partition) {
            if (partition) {
@@ -625,6 +621,20 @@ public final class VectorGraphics {
                 } while(pos < segmentLength);
             }
        }
+
+        // FEATURE: make this faster and cache it; also deal with negative coordinates
+        public int boundingBoxWidth() {
+            int ret = 0;
+            for(int i=0; i<numvertices; i++) ret = Math.max(ret, x[i]);
+            return ret;
+        }
+
+        // FEATURE: make this faster and cache it; also deal with negative coordinates
+        public int boundingBoxHeight() {
+            int ret = 0;
+            for(int i=0; i<numvertices; i++) ret = Math.max(ret, y[i]);
+            return ret;
+        }
     }