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.Assert; 32 import org.junit.Test; 33 34 import static org.junit.Assert.*; 35 import test.com.sun.javafx.test.TransformHelper; 36 import com.sun.javafx.geom.transform.Affine2D; 37 import com.sun.javafx.geom.transform.Affine3D; 38 import com.sun.javafx.geom.transform.BaseTransform; 39 import javafx.scene.transform.Scale; 40 import javafx.scene.transform.Transform; 41 import test.javafx.scene.transform.TransformTest; 42 43 public class ScaleTest { 44 45 @Test 46 public void testScale() { 47 final Scale trans = new Scale() {{ 48 setX(25); 49 setY(52); 50 }}; 51 final Rectangle n = new Rectangle(); 52 n.getTransforms().add(trans); 53 54 assertTx(n, BaseTransform.getScaleInstance(25, 52)); 55 TransformHelper.assertMatrix(trans, 56 25, 0, 0, 0, 57 0, 52, 0, 0, 58 0, 0, 1, 0); 59 60 61 trans.setX(34); 62 Assert.assertEquals(34, trans.getX(), 1e-100); 63 assertTx(n, BaseTransform.getScaleInstance(34, 52)); 64 TransformHelper.assertMatrix(trans, 65 34, 0, 0, 0, 66 0, 52, 0, 0, 67 0, 0, 1, 0); 68 69 70 trans.setY(67); 71 assertTx(n, BaseTransform.getScaleInstance(34, 67)); 72 TransformHelper.assertMatrix(trans, 73 34, 0, 0, 0, 74 0, 67, 0, 0, 75 0, 0, 1, 0); 76 77 78 trans.setPivotX(66); 79 80 Affine2D expTx = new Affine2D(); 81 expTx.setToTranslation(trans.getPivotX(), trans.getPivotY()); 82 expTx.scale(trans.getX(), trans.getY()); 83 expTx.translate(-trans.getPivotX(), -trans.getPivotY()); 84 assertTx(n, expTx); 85 TransformHelper.assertMatrix(trans, 86 34, 0, 0, -2178, 87 0, 67, 0, 0, 88 0, 0, 1, 0); 89 90 91 trans.setPivotY(77); 92 93 expTx.setToTranslation(trans.getPivotX(), trans.getPivotY()); 94 expTx.scale(trans.getX(), trans.getY()); 95 expTx.translate(-trans.getPivotX(), -trans.getPivotY()); 96 assertTx(n, expTx); 97 TransformHelper.assertMatrix(trans, 98 34, 0, 0, -2178, 99 0, 67, 0, -5082, 100 0, 0, 1, 0); 101 102 trans.setZ(10); 103 trans.setPivotZ(5); 104 TransformHelper.assertMatrix(trans, 105 34, 0, 0, -2178, 106 0, 67, 0, -5082, 107 0, 0, 10, -45); 108 } 109 110 @Test public void testScalePivotCtor() { 111 final Scale trans = new Scale(11, 22, 33, 44); 112 final Rectangle n = new Rectangle(); 113 n.getTransforms().add(trans); 114 115 Affine2D expT = new Affine2D(); 116 expT.translate(33, 44); 117 expT.scale(11, 22); 118 expT.translate(-33, -44); 119 assertTx(n, expT); 120 } 121 122 @Test public void testScalePivotCtor3D() { 123 final Scale trans = new Scale(11, 22, 33, 44, 55, 66); 124 final Rectangle n = new Rectangle(); 125 n.getTransforms().add(trans); 126 127 Affine3D expT = new Affine3D(); 128 expT.translate(44, 55, 66); 129 expT.scale(11, 22, 33); 130 expT.translate(-44, -55, -66); 131 assertTx(n, expT); 132 } 133 134 @Test 135 public void testCopying() { 136 final Scale trans = new Scale(34, 67, 10, 66, 77, 5); 137 138 Transform copy = trans.clone(); 139 140 TransformHelper.assertMatrix(copy, 141 34, 0, 0, -2178, 142 0, 67, 0, -5082, 143 0, 0, 10, -45); 144 } 145 146 @Test public void testToString() { 147 final Scale trans = new Scale(5, 8); 148 149 String s = trans.toString(); 150 151 assertNotNull(s); 152 assertFalse(s.isEmpty()); 153 } 154 155 @Test public void testBoundPropertySynced_PivotX() throws Exception { 156 TransformTest.checkDoublePropertySynced(new Scale(3, 3, 0), "pivotX", 200.0); 157 } 158 159 @Test public void testBoundPropertySynced_PivotY() throws Exception { 160 TransformTest.checkDoublePropertySynced(new Scale(3, 3, 0), "pivotY", 200.0); 161 } 162 163 @Test public void testBoundPropertySynced_PivotZ() throws Exception { 164 TransformTest.checkDoublePropertySynced(new Scale(3, 3, 0), "pivotZ", 20.0); 165 } 166 167 @Test public void testBoundPropertySynced_X() throws Exception { 168 TransformTest.checkDoublePropertySynced(new Scale(3, 3, 0), "x", 123.0); 169 } 170 171 @Test public void testBoundPropertySynced_Y() throws Exception { 172 TransformTest.checkDoublePropertySynced(new Scale(3, 3, 0), "y", 123.0); 173 } 174 175 @Test public void testBoundPropertySynced_Z() throws Exception { 176 TransformTest.checkDoublePropertySynced(new Scale(3, 3, 0), "z", 123.0); 177 } 178 }