1 /*
   2  * Copyright (c) 2011, 2013, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.transform;
  27 
  28 import static javafx.scene.transform.TransformTest.assertTx;
  29 import javafx.scene.shape.Rectangle;
  30 
  31 import org.junit.Test;
  32 import static org.junit.Assert.*;
  33 
  34 import com.sun.javafx.test.TransformHelper;
  35 import com.sun.javafx.geom.transform.Affine2D;
  36 
  37 public class ShearTest {
  38 
  39     @Test
  40     public void testShear() {
  41         final Shear t = new Shear(112, 114);
  42         final Rectangle rect = new Rectangle();
  43         rect.getTransforms().add(t);
  44         Affine2D expT = new Affine2D();
  45         expT.setToShear(112, 114);
  46         assertTx(rect, expT);
  47 
  48         final Shear trans = new Shear() {{
  49             setX(25);
  50             setY(52);
  51         }};
  52         final Rectangle n = new Rectangle();
  53         n.getTransforms().add(trans);
  54 
  55         TransformHelper.assertMatrix(trans,
  56                  1, 25, 0, 0,
  57                 52,  1, 0, 0,
  58                  0,  0, 1, 0);
  59 
  60         Affine2D expTx1 = new Affine2D();
  61         expTx1.setToShear(25, 52);
  62         assertTx(n, expTx1);
  63 
  64         trans.setX(34);
  65         Affine2D expTx2 = new Affine2D();
  66         expTx2.setToShear(34, 52);
  67         assertTx(n, expTx2);
  68         TransformHelper.assertMatrix(trans,
  69                  1, 34, 0, 0,
  70                 52,  1, 0, 0,
  71                  0,  0, 1, 0);
  72 
  73         trans.setY(67);
  74         Affine2D expTx3 = new Affine2D();
  75         expTx3.setToShear(34, 67);
  76         assertTx(n, expTx3);
  77         TransformHelper.assertMatrix(trans,
  78                  1, 34, 0, 0,
  79                 67,  1, 0, 0,
  80                  0,  0, 1, 0);
  81 
  82         trans.setPivotX(66);
  83 
  84         Affine2D expTx = new Affine2D();
  85         expTx.setToTranslation(trans.getPivotX(), trans.getPivotY());
  86         expTx.shear(trans.getX(), trans.getY());
  87         expTx.translate(-trans.getPivotX(), -trans.getPivotY());
  88         assertTx(n, expTx);
  89         TransformHelper.assertMatrix(trans,
  90                  1, 34, 0,      0,
  91                 67,  1, 0, -67*66,
  92                  0,  0, 1,      0);
  93 
  94 
  95         trans.setPivotY(77);
  96 
  97         expTx.setToTranslation(trans.getPivotX(), trans.getPivotY());
  98         expTx.shear(trans.getX(), trans.getY());
  99         expTx.translate(-trans.getPivotX(), -trans.getPivotY());
 100         assertTx(n, expTx);
 101         TransformHelper.assertMatrix(trans,
 102                  1, 34, 0, -34*77,
 103                 67,  1, 0, -67*66,
 104                  0,  0, 1,      0);
 105     }
 106 
 107     @Test
 108     public void testCopying() {
 109         final Shear trans = new Shear(34, 67, 66, 77);
 110 
 111         Transform copy = trans.clone();
 112 
 113         TransformHelper.assertMatrix(copy,
 114                  1, 34, 0, -34*77,
 115                 67,  1, 0, -67*66,
 116                  0,  0, 1,      0);
 117     }
 118 
 119     @Test public void testToString() {
 120         final Shear trans = new Shear(8, 15);
 121 
 122         String s = trans.toString();
 123 
 124         assertNotNull(s);
 125         assertFalse(s.isEmpty());
 126     }
 127 
 128     @Test public void testBoundPropertySynced_X() throws Exception {
 129         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "x", 123.0);
 130     }
 131 
 132     @Test public void testBoundPropertySynced_Y() throws Exception {
 133         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "y", 112.0);
 134     }
 135 
 136     @Test public void testBoundPropertySynced_PivotX() throws Exception {
 137         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "pivotX", 22.0);
 138     }
 139 
 140     @Test public void testBoundPropertySynced_PivotY() throws Exception {
 141         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "pivotY", 33.0);
 142     }
 143 }