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