test/java/awt/geom/AffineTransform/TestInvertMethods.java

Print this page


   1 /*
   2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 4987374
  27  * @summary Unit test for inversion methods:
  28  *
  29  *          AffineTransform.createInverse();
  30  *          AffineTransform.invert();
  31  *
  32  * @author flar
  33  * @run main TestInvertMethods
  34  */
  35 
  36 import java.awt.geom.AffineTransform;
  37 import java.awt.geom.NoninvertibleTransformException;
  38 
  39 /*
  40  * Instances of the inner class Tester are "nodes" which take an input
  41  * AffineTransform (AT), modify it in some way and pass the modified
  42  * AT onto another Tester node.
  43  *
  44  * There is one particular Tester node of note called theVerifier.
  45  * This is a leaf node which takes the input AT and tests the various
  46  * inversion methods on that matrix.


 171         };
 172 
 173         /*
 174          * The inversion math may work out fairly exactly, but when
 175          * we concatenate the inversions back with the original matrix
 176          * in an attempt to restore them to the identity matrix,
 177          * then we can end up compounding errors to a fairly high
 178          * level, particularly if the component values had mantissas
 179          * that were repeating fractions.  This function therefore
 180          * "fixes" the results of concatenating the inversions back
 181          * with their original matrices to get rid of small variations
 182          * in the values that should have ended up being 0.0.
 183          */
 184         public void concatfix(AffineTransform at) {
 185             double m00 = at.getScaleX();
 186             double m10 = at.getShearY();
 187             double m01 = at.getShearX();
 188             double m11 = at.getScaleY();
 189             double m02 = at.getTranslateX();
 190             double m12 = at.getTranslateY();


 191             if (Math.abs(m02) < 1E-10) m02 = 0.0;
 192             if (Math.abs(m12) < 1E-10) m12 = 0.0;
 193             if (Math.abs(m01) < 1E-15) m01 = 0.0;
 194             if (Math.abs(m10) < 1E-15) m10 = 0.0;
 195             at.setTransform(m00, m10,
 196                             m01, m11,
 197                             m02, m12);
 198         }
 199 
 200         public void test(boolean full) {
 201             test(IdentityTx, full);
 202         }
 203 
 204         public void test(AffineTransform init, boolean full) {
 205             test(init, theVerifier, full);
 206         }
 207 
 208         public void test(AffineTransform init, Tester next, boolean full) {
 209             next.test(init, full);
 210         }


 256         }
 257 
 258         /*
 259          * NOP node.
 260          */
 261         public static class Identity extends Tester {
 262             public void test(AffineTransform init, Tester next, boolean full) {
 263                 if (verbose) System.out.println("*Identity = "+init);
 264                 next.test(init, full);
 265             }
 266         }
 267 
 268         /*
 269          * Affine rotation node.
 270          */
 271         public static class Rotate extends Tester {
 272             public void test(AffineTransform init, Tester next, boolean full) {
 273                 int inc = full ? 10 : 45;
 274                 for (int i = -720; i <= 720; i += inc) {
 275                     AffineTransform at2 = new AffineTransform(init);
 276                     at2.rotate(Math.toRadians(i));
 277                     if (verbose) System.out.println("*Rotate("+i+") = "+at2);
 278                     next.test(at2, full);
 279                 }
 280             }
 281         }
 282 
 283         public static final double SMALL_VALUE = .0001;
 284         public static final double LARGE_VALUE = 10000;
 285 
 286         /*
 287          * Affine scale node.
 288          */
 289         public static class Scale extends Tester {
 290             public double fullvals[] = {
 291                 // Noninvertibles
 292                 0.0, 0.0,
 293                 0.0, 1.0,
 294                 1.0, 0.0,
 295 
 296                 // Invertibles


   1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 4987374 8062163
  27  * @summary Unit test for inversion methods:
  28  *
  29  *          AffineTransform.createInverse();
  30  *          AffineTransform.invert();
  31  *
  32  * @author flar
  33  * @run main TestInvertMethods
  34  */
  35 
  36 import java.awt.geom.AffineTransform;
  37 import java.awt.geom.NoninvertibleTransformException;
  38 
  39 /*
  40  * Instances of the inner class Tester are "nodes" which take an input
  41  * AffineTransform (AT), modify it in some way and pass the modified
  42  * AT onto another Tester node.
  43  *
  44  * There is one particular Tester node of note called theVerifier.
  45  * This is a leaf node which takes the input AT and tests the various
  46  * inversion methods on that matrix.


 171         };
 172 
 173         /*
 174          * The inversion math may work out fairly exactly, but when
 175          * we concatenate the inversions back with the original matrix
 176          * in an attempt to restore them to the identity matrix,
 177          * then we can end up compounding errors to a fairly high
 178          * level, particularly if the component values had mantissas
 179          * that were repeating fractions.  This function therefore
 180          * "fixes" the results of concatenating the inversions back
 181          * with their original matrices to get rid of small variations
 182          * in the values that should have ended up being 0.0.
 183          */
 184         public void concatfix(AffineTransform at) {
 185             double m00 = at.getScaleX();
 186             double m10 = at.getShearY();
 187             double m01 = at.getShearX();
 188             double m11 = at.getScaleY();
 189             double m02 = at.getTranslateX();
 190             double m12 = at.getTranslateY();
 191             if (Math.abs(m00-1.0) < 1E-10) m00 = 1.0;
 192             if (Math.abs(m11-1.0) < 1E-10) m11 = 1.0;
 193             if (Math.abs(m02) < 1E-10) m02 = 0.0;
 194             if (Math.abs(m12) < 1E-10) m12 = 0.0;
 195             if (Math.abs(m01) < 1E-15) m01 = 0.0;
 196             if (Math.abs(m10) < 1E-15) m10 = 0.0;
 197             at.setTransform(m00, m10,
 198                             m01, m11,
 199                             m02, m12);
 200         }
 201 
 202         public void test(boolean full) {
 203             test(IdentityTx, full);
 204         }
 205 
 206         public void test(AffineTransform init, boolean full) {
 207             test(init, theVerifier, full);
 208         }
 209 
 210         public void test(AffineTransform init, Tester next, boolean full) {
 211             next.test(init, full);
 212         }


 258         }
 259 
 260         /*
 261          * NOP node.
 262          */
 263         public static class Identity extends Tester {
 264             public void test(AffineTransform init, Tester next, boolean full) {
 265                 if (verbose) System.out.println("*Identity = "+init);
 266                 next.test(init, full);
 267             }
 268         }
 269 
 270         /*
 271          * Affine rotation node.
 272          */
 273         public static class Rotate extends Tester {
 274             public void test(AffineTransform init, Tester next, boolean full) {
 275                 int inc = full ? 10 : 45;
 276                 for (int i = -720; i <= 720; i += inc) {
 277                     AffineTransform at2 = new AffineTransform(init);
 278                     at2.rotate(i / 180.0 * Math.PI);
 279                     if (verbose) System.out.println("*Rotate("+i+") = "+at2);
 280                     next.test(at2, full);
 281                 }
 282             }
 283         }
 284 
 285         public static final double SMALL_VALUE = .0001;
 286         public static final double LARGE_VALUE = 10000;
 287 
 288         /*
 289          * Affine scale node.
 290          */
 291         public static class Scale extends Tester {
 292             public double fullvals[] = {
 293                 // Noninvertibles
 294                 0.0, 0.0,
 295                 0.0, 1.0,
 296                 1.0, 0.0,
 297 
 298                 // Invertibles