harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r501467 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/geom/AffineTransform.java test/api/java/common/java/awt/geom/AffineTransformTest.java test/api/java/common/java/awt/geom/GeomTestCase.java
Date Tue, 30 Jan 2007 16:54:22 GMT
Author: apetrenko
Date: Tue Jan 30 08:54:20 2007
New Revision: 501467

URL: http://svn.apache.org/viewvc?view=rev&rev=501467
Log:
Patch for HARMONY-1603 "[classlib][awt] AffineTransform.transform(float[], int, float[], int,
int) result deffers from RI if src and dst are the same array"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/geom/AffineTransform.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/geom/AffineTransform.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/geom/AffineTransform.java?view=diff&rev=501467&r1=501466&r2=501467
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/geom/AffineTransform.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/geom/AffineTransform.java
Tue Jan 30 08:54:20 2007
@@ -439,24 +439,40 @@
         }
     }
     
-    public void transform(double[] src, int srcOff, double[] dst, int dstOff, int length)
{
+     public void transform(double[] src, int srcOff, double[] dst, int dstOff, int length)
{
+        int step = 2;
+        if (src == dst && srcOff < dstOff && dstOff < srcOff + length
* 2) {
+            srcOff = srcOff + length * 2 - 2;
+            dstOff = dstOff + length * 2 - 2;
+            step = -2;
+        }
         while (--length >= 0) {
-            double x = src[srcOff++];
-            double y = src[srcOff++];
-            dst[dstOff++] = x * m00 + y * m01 + m02;
-            dst[dstOff++] = x * m10 + y * m11 + m12;
+            double x = src[srcOff + 0];
+            double y = src[srcOff + 1];
+            dst[dstOff + 0] = x * m00 + y * m01 + m02;
+            dst[dstOff + 1] = x * m10 + y * m11 + m12;
+            srcOff += step;
+            dstOff += step;
         }
     }
 
     public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) {
+        int step = 2;
+        if (src == dst && srcOff < dstOff && dstOff < srcOff + length
* 2) {
+            srcOff = srcOff + length * 2 - 2;
+            dstOff = dstOff + length * 2 - 2;
+            step = -2;
+        }
         while (--length >= 0) {
-            float x = src[srcOff++];
-            float y = src[srcOff++];
-            dst[dstOff++] = (float)(x * m00 + y * m01 + m02);
-            dst[dstOff++] = (float)(x * m10 + y * m11 + m12);
+            float x = src[srcOff + 0];
+            float y = src[srcOff + 1];
+            dst[dstOff + 0] = (float)(x * m00 + y * m01 + m02);
+            dst[dstOff + 1] = (float)(x * m10 + y * m11 + m12);
+            srcOff += step;
+            dstOff += step;
         }
     }
-
+    
     public void transform(float[] src, int srcOff, double[] dst, int dstOff, int length)
{
         while (--length >= 0) {
             float x = src[srcOff++];

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java?view=diff&rev=501467&r1=501466&r2=501467
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java
Tue Jan 30 08:54:20 2007
@@ -615,7 +615,7 @@
         }
     }
 
-    public void testTransform1() {
+    public void testTransformPoint() {
         for (float[][] element : points) {
             AffineTransform at = new AffineTransform(element[0]);
             for(int j = 1; j < element.length; j++) {
@@ -684,7 +684,7 @@
         }        
     }
     
-    public void testTransform3() {
+    public void testTransformArray2() {
         AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4);
         double[] src = new double[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0};
         double[] dst = new double[6];
@@ -692,8 +692,8 @@
         at.transform(src, 4, dst, 2, 2);
         assertEquals(expected, dst, 6, 0.0);
     }
-
-    public void testTransform4() {
+    
+    public void testTransformArray3() {
         AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4);
         float[] src = new float[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0};
         float[] dst = new float[6];
@@ -702,7 +702,7 @@
         assertEquals(expected, dst, 6, 0.0f);
     }
 
-    public void testTransform5() {
+    public void testTransformArray4() {
         AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4);
         float[] src = new float[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0};
         double[] dst = new double[6];
@@ -711,13 +711,31 @@
         assertEquals(expected, dst, 6, 0.0);
     }
 
-    public void testTransform6() {
+    public void testTransformArray5() {
         AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4);
         double[] src = new double[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0};
         float[] dst = new float[6];
         float[] expected = new float[]{0, 0, 3, 4, 1, 5};
         at.transform(src, 4, dst, 2, 2);
         assertEquals(expected, dst, 6, 0.0f);
+    }
+    
+    public void testTransformArrayOverlap1() {
+        // Regresion test HARMONY-1603
+        AffineTransform at = AffineTransform.getTranslateInstance(2, 3);
+        float[] src = new float[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
+        float[] expected = new float[]{1, 2, 3, 4, 3, 5, 5, 7, 7, 9, 9, 11, 13, 14};
+        at.transform(src, 0, src, 4, 4);
+        assertEquals(expected, src, src.length, 0);
+    }
+
+    public void testTransformArrayOverlap2() {
+        // Regresion test HARMONY-1603
+        AffineTransform at = AffineTransform.getTranslateInstance(2, 3);
+        double[] src = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
+        double[] expected = new double[]{1, 2, 3, 4, 3, 5, 5, 7, 7, 9, 9, 11, 13, 14};
+        at.transform(src, 0, src, 4, 4);
+        assertEquals(expected, src, src.length, 0);
     }
 
     public void testDeltaTransform1() {

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java?view=diff&rev=501467&r1=501466&r2=501467
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java
Tue Jan 30 08:54:20 2007
@@ -22,6 +22,7 @@
 
 import java.awt.SerializeTestCase;
 import java.awt.Tools;
+import java.util.Arrays;
 
 public class GeomTestCase extends SerializeTestCase {
 
@@ -142,7 +143,9 @@
             fail(concat(msg, "Wrong array length " + a2.length + ", needed at least " + length));
         }
         for(int i = 0; i < length; i++) {
-            assertEquals(concat(msg, "Element " + i), a1[i], a2[i], delta);
+            if (a1[i] != a2[i]) {
+                fail(msg, Arrays.toString(a1), Arrays.toString(a2));
+            }
         }
     }
 
@@ -158,7 +161,9 @@
             fail(concat(msg, "Wrong array length " + a2.length + ", needed at least " + length));
         }
         for(int i = 0; i < length; i++) {
-            assertEquals(concat(msg, "Element " + i), a1[i], a2[i], delta);
+            if (a1[i] != a2[i]) {
+                fail(msg, Arrays.toString(a1), Arrays.toString(a2));
+            }
         }
     }
 
@@ -174,7 +179,9 @@
             fail(concat(msg, "Wrong array length " + a2.length + ", needed at least " + length));
         }
         for(int i = 0; i < length; i++) {
-            assertEquals(concat(msg, "Element " + i), a1[i], a2[i]);
+            if (a1[i] != a2[i]) {
+                fail(msg, Arrays.toString(a1), Arrays.toString(a2));
+            }
         }
     }
 



Mime
View raw message