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.com.sun.javafx.geom; 27 28 import com.sun.javafx.geom.BoxBounds; 29 import com.sun.javafx.geom.RectBounds; 30 import com.sun.javafx.geom.Rectangle; 31 import static junit.framework.Assert.assertTrue; 32 import static junit.framework.Assert.assertFalse; 33 import static junit.framework.Assert.assertEquals; 34 35 import org.junit.Test; 36 37 public class BaseBoundsTest { 38 39 public @Test 40 void testBounds_MakeEmptyTest() { 41 RectBounds rectBounds = new RectBounds(10, 20, 20, 30); 42 assertFalse(rectBounds.isEmpty()); 43 rectBounds.makeEmpty(); 44 assertTrue(rectBounds.isEmpty()); 45 assertEquals(new RectBounds(), rectBounds); 46 47 BoxBounds boxBounds = new BoxBounds(10, 20, 10, 40, 50, 20); 48 assertFalse(boxBounds.isEmpty()); 49 boxBounds.makeEmpty(); 50 assertTrue(boxBounds.isEmpty()); 51 assertEquals(new BoxBounds(), boxBounds); 52 } 53 54 public @Test 55 void testRectangle_ZeroArea() { 56 RectBounds rectBounds = new RectBounds(new Rectangle()); 57 assertFalse(rectBounds.isEmpty()); 58 RectBounds rectBounds2 = new RectBounds(0, 0, 0, 0); 59 assertEquals(rectBounds, rectBounds2); 60 } 61 62 public @Test 63 void testRectangle_Offset() { 64 // the arguments are (x, y, width, height) 65 Rectangle rect = new Rectangle(10, 20, 40, 50); 66 RectBounds rectBounds = new RectBounds(rect); 67 assertFalse(rectBounds.isEmpty()); 68 69 // the arguments are (minX, minY, maxX, maxY) 70 RectBounds rectBounds2 = new RectBounds(10, 20, 50, 70); 71 assertEquals(rectBounds, rectBounds2); 72 } 73 74 public @Test 75 void testBounds_IntersectsTest1() { 76 RectBounds rectBounds = new RectBounds(10, 20, 40, 50); 77 assertTrue(rectBounds.is2D()); 78 assertFalse(rectBounds.isEmpty()); 79 80 BoxBounds boxBounds = new BoxBounds(10, 20, 0, 20, 30, 0); 81 assertTrue(boxBounds.is2D()); 82 assertTrue(boxBounds.intersects(rectBounds)); 83 84 boxBounds = new BoxBounds(10, 20, 2, 20, 30, 2); 85 assertFalse(boxBounds.is2D()); 86 assertFalse(boxBounds.intersects(rectBounds)); 87 } 88 89 public @Test 90 void testBounds_IntersectsTest2() { 91 RectBounds rectBounds = new RectBounds(10, 20, 40, 50); 92 assertFalse(rectBounds.isEmpty()); 93 94 BoxBounds boxBounds = new BoxBounds(10, 20, 1, 20, 30, 1); 95 assertFalse(boxBounds.intersects(rectBounds)); 96 } 97 98 public @Test 99 void testBounds_IntersectsTest3() { 100 BoxBounds boxBounds = new BoxBounds(10, 20, 10, 40, 50, 20); 101 assertFalse(boxBounds.isEmpty()); 102 103 BoxBounds boxBounds2 = new BoxBounds(10, 20, 0, 20, 30, 5); 104 assertFalse(boxBounds2.intersects(boxBounds)); 105 } 106 107 public @Test 108 void testBounds_IntersectsTest4() { 109 BoxBounds boxBounds = new BoxBounds(10, 20, 10, 40, 50, 20); 110 assertFalse(boxBounds.isEmpty()); 111 112 BoxBounds boxBounds2 = new BoxBounds(10, 20, 0, 20, 30, 10); 113 assertTrue(boxBounds2.intersects(boxBounds)); 114 } 115 116 public @Test 117 void testBounds_SetBoundsAndSortTest() { 118 RectBounds rectBounds = new RectBounds(); 119 assertTrue(rectBounds.isEmpty()); 120 rectBounds.setBoundsAndSort(20, 30, 10, 20); 121 assertFalse(rectBounds.isEmpty()); 122 assertEquals(new RectBounds(10, 20, 20, 30), rectBounds); 123 124 BoxBounds boxBounds = new BoxBounds(); 125 assertTrue(boxBounds.isEmpty()); 126 boxBounds.setBoundsAndSort(40, 50, 20, 10, 20, 10); 127 assertFalse(boxBounds.isEmpty()); 128 assertEquals(new BoxBounds(10, 20, 10, 40, 50, 20), boxBounds); 129 } 130 131 public @Test 132 void testBounds_UnionWithTest() { 133 RectBounds rectBounds = new RectBounds(); 134 assertTrue(rectBounds.isEmpty()); 135 RectBounds rectBounds2 = new RectBounds(0, 1, 2, 4); 136 rectBounds.unionWith(rectBounds2); 137 assertFalse(rectBounds.isEmpty()); 138 assertEquals(new RectBounds(0, 1, 2, 4), rectBounds); 139 RectBounds rectBounds3 = new RectBounds(-1, -2, 2, 3); 140 rectBounds.unionWith(rectBounds3); 141 assertEquals(new RectBounds(-1, -2, 2, 4), rectBounds); 142 143 BoxBounds boxBounds = new BoxBounds(); 144 assertTrue(boxBounds.isEmpty()); 145 BoxBounds boxBounds2 = new BoxBounds(0, 1, 2, 2, 3, 4); 146 boxBounds.unionWith(boxBounds2); 147 assertFalse(boxBounds.isEmpty()); 148 assertEquals(new BoxBounds(0, 1, 2, 2, 3, 4), boxBounds); 149 BoxBounds boxBounds3 = new BoxBounds(-1, -2, -3, 1, 2, 3); 150 boxBounds.unionWith(boxBounds3); 151 assertEquals(new BoxBounds(-1, -2, -3, 2, 3, 4), boxBounds); 152 } 153 154 }