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