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 
  30 import com.sun.javafx.FXUnit;
  31 import javafx.scene.shape.Rectangle;
  32 
  33 import org.junit.Rule;
  34 import org.junit.Test;
  35 import static org.junit.Assert.*;
  36 
  37 import com.sun.javafx.test.TransformHelper;
  38 import com.sun.javafx.geom.transform.Affine2D;
  39 
  40 public class ShearTest {
  41 
  42     @Rule
  43     public FXUnit fx = new FXUnit();
  44 
  45     @Test
  46     public void testShear() {
  47         final Shear t = new Shear(112, 114);
  48         final Rectangle rect = new Rectangle();
  49         rect.getTransforms().add(t);
  50         Affine2D expT = new Affine2D();
  51         expT.setToShear(112, 114);
  52         assertTx(rect, expT);
  53 
  54         final Shear trans = new Shear() {{
  55             setX(25);
  56             setY(52);
  57         }};
  58         final Rectangle n = new Rectangle();
  59         n.getTransforms().add(trans);
  60 
  61         TransformHelper.assertMatrix(trans,
  62                  1, 25, 0, 0,
  63                 52,  1, 0, 0,
  64                  0,  0, 1, 0);
  65 
  66         Affine2D expTx1 = new Affine2D();
  67         expTx1.setToShear(25, 52);
  68         assertTx(n, expTx1);
  69 
  70         trans.setX(34);
  71         Affine2D expTx2 = new Affine2D();
  72         expTx2.setToShear(34, 52);
  73         assertTx(n, expTx2);
  74         TransformHelper.assertMatrix(trans,
  75                  1, 34, 0, 0,
  76                 52,  1, 0, 0,
  77                  0,  0, 1, 0);
  78 
  79         trans.setY(67);
  80         Affine2D expTx3 = new Affine2D();
  81         expTx3.setToShear(34, 67);
  82         assertTx(n, expTx3);
  83         TransformHelper.assertMatrix(trans,
  84                  1, 34, 0, 0,
  85                 67,  1, 0, 0,
  86                  0,  0, 1, 0);
  87 
  88         trans.setPivotX(66);
  89 
  90         Affine2D expTx = new Affine2D();
  91         expTx.setToTranslation(trans.getPivotX(), trans.getPivotY());
  92         expTx.shear(trans.getX(), trans.getY());
  93         expTx.translate(-trans.getPivotX(), -trans.getPivotY());
  94         assertTx(n, expTx);
  95         TransformHelper.assertMatrix(trans,
  96                  1, 34, 0,      0,
  97                 67,  1, 0, -67*66,
  98                  0,  0, 1,      0);
  99 
 100 
 101         trans.setPivotY(77);
 102 
 103         expTx.setToTranslation(trans.getPivotX(), trans.getPivotY());
 104         expTx.shear(trans.getX(), trans.getY());
 105         expTx.translate(-trans.getPivotX(), -trans.getPivotY());
 106         assertTx(n, expTx);
 107         TransformHelper.assertMatrix(trans,
 108                  1, 34, 0, -34*77,
 109                 67,  1, 0, -67*66,
 110                  0,  0, 1,      0);
 111     }
 112 
 113     @Test
 114     public void testCopying() {
 115         final Shear trans = new Shear(34, 67, 66, 77);
 116 
 117         Transform copy = trans.clone();
 118 
 119         TransformHelper.assertMatrix(copy,
 120                  1, 34, 0, -34*77,
 121                 67,  1, 0, -67*66,
 122                  0,  0, 1,      0);
 123     }
 124 
 125     @Test public void testToString() {
 126         final Shear trans = new Shear(8, 15);
 127 
 128         String s = trans.toString();
 129 
 130         assertNotNull(s);
 131         assertFalse(s.isEmpty());
 132     }
 133 
 134     @Test public void testBoundPropertySynced_X() throws Exception {
 135         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "x", 123.0);
 136     }
 137 
 138     @Test public void testBoundPropertySynced_Y() throws Exception {
 139         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "y", 112.0);
 140     }
 141 
 142     @Test public void testBoundPropertySynced_PivotX() throws Exception {
 143         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "pivotX", 22.0);
 144     }
 145 
 146     @Test public void testBoundPropertySynced_PivotY() throws Exception {
 147         TransformTest.checkDoublePropertySynced(new Shear(3, 3, 0, 0), "pivotY", 33.0);
 148     }
 149 }