1 /* 2 * Copyright (c) 2010, 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.geometry; 27 28 import javafx.geometry.BoundingBox; 29 import javafx.geometry.Bounds; 30 import javafx.geometry.Point2D; 31 import static org.junit.Assert.assertFalse; 32 import static org.junit.Assert.assertNotNull; 33 import static org.junit.Assert.assertTrue; 34 35 import org.junit.Test; 36 37 public class BoundingBoxTest { 38 @Test 39 public void testIsEmpty() { 40 assertFalse(new BoundingBox(0, 0, 0, 0).isEmpty()); 41 assertFalse(new BoundingBox(0, 0, 1, 0).isEmpty()); 42 assertFalse(new BoundingBox(0, 0, 0, 1).isEmpty()); 43 assertTrue(new BoundingBox(0, 0, -1, 0).isEmpty()); 44 assertTrue(new BoundingBox(0, 0, 0, -1).isEmpty()); 45 assertTrue(new BoundingBox(0, 0, -1, -1).isEmpty()); 46 assertFalse(new BoundingBox(0, 0, 1, 1).isEmpty()); 47 } 48 49 @Test 50 public void testIsEmpty3D() { 51 assertFalse(new BoundingBox(0, 0, 0, 0, 0, 0).isEmpty()); 52 assertFalse(new BoundingBox(0, 0, 0, 1, 0, 0).isEmpty()); 53 assertFalse(new BoundingBox(0, 0, 0, 0, 1, 0).isEmpty()); 54 assertFalse(new BoundingBox(0, 0, 0, 0, 0, 1).isEmpty()); 55 assertFalse(new BoundingBox(0, 0, 0, 1, 1, 1).isEmpty()); 56 assertTrue(new BoundingBox(0, 0, 0, -1, 0, 0).isEmpty()); 57 assertTrue(new BoundingBox(0, 0, 0, 0, -1, 0).isEmpty()); 58 assertTrue(new BoundingBox(0, 0, 0, 0, 0, -1).isEmpty()); 59 assertTrue(new BoundingBox(0, 0, 0, -1, -1, -1).isEmpty()); 60 } 61 62 @Test 63 public void testContains() { 64 BoundingBox bb = new BoundingBox(0, 0, 2, 2); 65 assertFalse(bb.contains((Point2D)null)); 66 assertTrue(bb.contains(new Point2D(1, 1))); 67 68 assertTrue(bb.contains(1, 1)); 69 assertFalse(bb.contains(3, 0)); 70 assertFalse(bb.contains(1, -1)); 71 assertFalse(bb.contains(1, 3)); 72 73 assertFalse(bb.contains((Bounds) null)); 74 assertTrue(bb.contains(new BoundingBox(1, 1, 1, 1))); 75 assertFalse(bb.contains(new BoundingBox(-1, 1, 1, 1))); 76 assertFalse(bb.contains(new BoundingBox(1, -1, 1, 1))); 77 assertFalse(bb.contains(new BoundingBox(1, 1, 2, 1))); 78 assertFalse(bb.contains(new BoundingBox(1, 1, 1, 2))); 79 80 assertTrue(bb.contains(1, 1, 1, 1)); 81 assertFalse(bb.contains(-1, 1, 1, 1)); 82 assertFalse(bb.contains(1, -1, 1, 1)); 83 assertFalse(bb.contains(1, 1, 2, 1)); 84 assertFalse(bb.contains(1, 1, 1, 2)); 85 } 86 87 @Test 88 public void testContains3D() { 89 BoundingBox bb = new BoundingBox(0, 0, 0, 2, 2, 1); 90 assertFalse(bb.contains((Point2D)null)); 91 assertTrue(bb.contains(new Point2D(1, 1))); 92 93 assertTrue(bb.contains(1, 1)); 94 assertFalse(bb.contains(3, 0)); 95 assertFalse(bb.contains(1, -1)); 96 assertFalse(bb.contains(1, 3)); 97 98 bb = new BoundingBox(0, 0, 0, 2, 2, 2); 99 assertFalse(bb.contains(1, 1, 3)); 100 assertTrue(bb.contains(1, 1, 1)); 101 102 assertFalse(bb.contains((Bounds) null)); 103 assertTrue(bb.contains(new BoundingBox(1, 1, 1, 1, 1, 1))); 104 assertFalse(bb.contains(new BoundingBox(-1, 1, 1, 1, 1, 1))); 105 assertFalse(bb.contains(new BoundingBox(1, -1, 1, 1, 1, 1))); 106 assertFalse(bb.contains(new BoundingBox(1, 1, 1, 2, 1, 1))); 107 assertFalse(bb.contains(new BoundingBox(1, 1, 1, 1, 2, 1))); 108 109 assertTrue(bb.contains(1, 1, 0, 1, 1, 2)); 110 assertFalse(bb.contains(-1, 1, 0, 1, 1, 2)); 111 assertFalse(bb.contains(1, -1, 0, 1, 1, 2)); 112 assertFalse(bb.contains(1, 1, 0, 2, 1, 2)); 113 assertFalse(bb.contains(1, 1, 0, 1, 2, 2)); 114 assertFalse(bb.contains(1, 1, 1, 1, 2, 3)); 115 } 116 117 @Test 118 public void testIntersects() { 119 BoundingBox bb = new BoundingBox(0, 0, 2, 2); 120 assertFalse(bb.intersects((Bounds) null)); 121 assertTrue(new BoundingBox(0, 0, 0, 0).intersects(bb)); 122 assertTrue(new BoundingBox(0, 0, 0, 0).intersects(0, 0, 0, 0)); 123 assertTrue(bb.intersects(1, 1, 1, 1)); 124 assertTrue(bb.intersects(new BoundingBox(1, 1, 1, 1))); 125 assertFalse(bb.intersects(3, 3, 3, 3)); 126 assertFalse(bb.intersects(new BoundingBox(-2, -2, 1, 1))); 127 } 128 129 @Test 130 public void testIntersects3D() { 131 BoundingBox bb = new BoundingBox(0, 0, 0, 2, 2, 1); 132 assertFalse(bb.intersects((Bounds) null)); 133 assertTrue(new BoundingBox(0, 0, 0, 0, 0, 1).intersects(bb)); 134 assertTrue(new BoundingBox(0, 0, 1, 0, 0, 1).intersects(0, 0, 1, 0, 0, 1)); 135 assertTrue(bb.intersects(1, 1, 1, 1, 1, 1)); 136 assertTrue(bb.intersects(new BoundingBox(1, 1, 1, 1, 1, 1))); 137 assertFalse(bb.intersects(3, 3, 0, 3, 3, 1)); 138 assertFalse(bb.intersects(new BoundingBox(-2, -2, 0, 1, 1, 1))); 139 } 140 141 @Test 142 public void testEquals() { 143 BoundingBox p1 = new BoundingBox(0, 0, 0, 0); 144 BoundingBox p2 = new BoundingBox(0, 1, 1, 1); 145 BoundingBox p3 = new BoundingBox(1, 0, 1, 1); 146 147 assertTrue(p1.equals(p1)); 148 assertTrue(p1.equals(new BoundingBox(0, 0, 0, 0))); 149 assertFalse(p1.equals(new Object())); 150 assertFalse(p1.equals(p2)); 151 assertFalse(p1.equals(p3)); 152 } 153 154 @Test 155 public void testEquals3D() { 156 BoundingBox p1 = new BoundingBox(0, 0, 0, 0, 0, 0); 157 BoundingBox p2 = new BoundingBox(0, 1, 1, 1, 1, 1); 158 BoundingBox p3 = new BoundingBox(1, 0, 1, 1, 1, 1); 159 BoundingBox p4 = new BoundingBox(0, 0, 0, 1, 1, 1); 160 BoundingBox p5 = new BoundingBox(0, 0, 0, 1, 1, 1); 161 162 assertTrue(p1.equals(p1)); 163 assertTrue(p1.equals(new BoundingBox(0, 0, 0, 0, 0, 0))); 164 assertFalse(p1.equals(new Object())); 165 assertFalse(p1.equals(p2)); 166 assertFalse(p1.equals(p3)); 167 assertTrue(p4.equals(p5)); 168 } 169 170 @Test 171 public void testToString() { 172 BoundingBox p1 = new BoundingBox(0, 0, 0, 0); 173 assertNotNull(p1.toString()); 174 } 175 }