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.bounds; 27 28 import static test.com.sun.javafx.test.TestHelper.assertSimilar; 29 import static test.com.sun.javafx.test.TestHelper.box; 30 import static org.junit.Assert.assertEquals; 31 import javafx.geometry.BoundingBox; 32 import javafx.scene.shape.Rectangle; 33 import javafx.scene.transform.Rotate; 34 35 import org.junit.Test; 36 37 public class Transformed3DBoundsTest { 38 39 /*************************************************************************** 40 * * Transform Tests * * These are tests related to transforming the basic 41 * node types including * Groups and Regions. It is assumed that the 42 * getBoundsInLocal() values * for these nodes are correct. * * / 43 **************************************************************************/ 44 45 public @Test 46 void test3DBoundsForTranslatedRectangle() { 47 Rectangle rect = new Rectangle(100, 100); 48 rect.setTranslateX(10); 49 rect.setTranslateY(10); 50 rect.setTranslateZ(10); 51 52 BoundingBox bb = box(0, 0, 0, 100, 100, 0); 53 BoundingBox tbb = box(10, 10, 10, 100, 100, 0); 54 55 assertEquals(bb, rect.getBoundsInLocal()); 56 assertEquals(tbb, rect.getBoundsInParent()); 57 assertEquals(rect.getBoundsInLocal(), rect.getLayoutBounds()); 58 59 assertSimilar(tbb, rect.localToParent(rect.getBoundsInLocal())); 60 assertSimilar(tbb, rect.localToScene(rect.getBoundsInLocal())); 61 assertSimilar(bb, rect.parentToLocal( 62 rect.localToParent(rect.getBoundsInLocal()))); 63 assertSimilar(bb, rect.sceneToLocal( 64 rect.localToScene(rect.getBoundsInLocal()))); 65 66 } 67 68 69 // this test specifically checks to make sure the minX,, width, height 70 // invariants are correct in this case 71 public @Test 72 void test3DBoundsForNegativeScaledRectangle() { 73 Rectangle rect = new Rectangle(100, 100); 74 rect.setScaleX(2); 75 rect.setScaleY(2); 76 rect.setScaleZ(2); 77 78 BoundingBox bb = box(0, 0, 0, 100, 100, 0); 79 BoundingBox tbb = box(-50, -50, 200, 200); 80 81 assertEquals(bb, rect.getBoundsInLocal()); 82 assertEquals(tbb, rect.getBoundsInParent()); 83 assertEquals(rect.getBoundsInLocal(), rect.getLayoutBounds()); 84 85 assertSimilar(tbb, rect.localToParent(rect.getBoundsInLocal())); 86 assertSimilar(tbb, rect.localToScene(rect.getBoundsInLocal())); 87 assertSimilar(bb, rect.parentToLocal( 88 rect.localToParent(rect.getBoundsInLocal()))); 89 assertSimilar(bb, rect.sceneToLocal( 90 rect.localToScene(rect.getBoundsInLocal()))); 91 } 92 93 public @Test 94 void testBoundsForXRotatedRectangle() { 95 Rectangle rect = new Rectangle(100, 100); 96 rect.setRotate(90); 97 rect.setRotationAxis(Rotate.X_AXIS); 98 99 BoundingBox bb = box(0, 0, 0, 100, 100, 0); 100 BoundingBox tbb = box(0, 50, -50, 100, 0, 100); 101 102 assertEquals(bb, rect.getBoundsInLocal()); 103 assertSimilar(tbb, rect.getBoundsInParent()); 104 assertEquals(rect.getBoundsInLocal(), rect.getLayoutBounds()); 105 106 assertSimilar(tbb, rect.localToParent(rect.getBoundsInLocal())); 107 assertSimilar(tbb, rect.localToScene(rect.getBoundsInLocal())); 108 assertSimilar(bb, rect.parentToLocal( 109 rect.localToParent(rect.getBoundsInLocal()))); 110 assertSimilar(bb, rect.sceneToLocal( 111 rect.localToScene(rect.getBoundsInLocal()))); 112 } 113 114 public @Test 115 void testBoundsForYRotatedRectangle() { 116 Rectangle rect = new Rectangle(100, 100); 117 rect.setRotate(90); 118 rect.setRotationAxis(Rotate.Y_AXIS); 119 120 BoundingBox bb = box(0, 0, 0, 100, 100, 0); 121 BoundingBox tbb = box(50, 0, -50, 0, 100, 100); 122 123 assertEquals(bb, rect.getBoundsInLocal()); 124 assertSimilar(tbb, rect.getBoundsInParent()); 125 assertEquals(rect.getBoundsInLocal(), rect.getLayoutBounds()); 126 127 assertSimilar(tbb, rect.localToParent(rect.getBoundsInLocal())); 128 assertSimilar(tbb, rect.localToScene(rect.getBoundsInLocal())); 129 assertSimilar(bb, rect.parentToLocal( 130 rect.localToParent(rect.getBoundsInLocal()))); 131 assertSimilar(bb, rect.sceneToLocal( 132 rect.localToScene(rect.getBoundsInLocal()))); 133 } 134 135 public @Test 136 void testBoundsForZRotatedRectangle() { 137 Rectangle rect = new Rectangle(100, 100); 138 rect.setRotate(90); 139 rect.setRotationAxis(Rotate.Z_AXIS); 140 141 BoundingBox bb = box(0, 0, 0, 100, 100, 0); 142 BoundingBox tbb = box(0, 0, 0, 100, 100, 0); 143 144 assertEquals(bb, rect.getBoundsInLocal()); 145 assertSimilar(tbb, rect.getBoundsInParent()); 146 assertEquals(rect.getBoundsInLocal(), rect.getLayoutBounds()); 147 148 assertSimilar(tbb, rect.localToParent(rect.getBoundsInLocal())); 149 assertSimilar(tbb, rect.localToScene(rect.getBoundsInLocal())); 150 assertSimilar(bb, rect.parentToLocal( 151 rect.localToParent(rect.getBoundsInLocal()))); 152 assertSimilar(bb, rect.sceneToLocal( 153 rect.localToScene(rect.getBoundsInLocal()))); 154 } 155 156 //TODO: Need to add more 3D Bounds testing here ... 157 }