1 44 45 package org.jfree.util.junit; 46 47 import java.awt.Polygon ; 48 import java.awt.Shape ; 49 import java.awt.geom.Arc2D ; 50 import java.awt.geom.Ellipse2D ; 51 import java.awt.geom.GeneralPath ; 52 import java.awt.geom.Line2D ; 53 import java.awt.geom.Rectangle2D ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.util.ShapeUtilities; 60 61 64 public class ShapeUtilitiesTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(ShapeUtilitiesTests.class); 73 } 74 75 80 public ShapeUtilitiesTests(final String name) { 81 super(name); 82 } 83 84 87 public void testEqualLine2Ds() { 88 89 assertTrue(ShapeUtilities.equal((Line2D ) null, (Line2D ) null)); 91 Line2D l1 = new Line2D.Float (1.0f, 2.0f, 3.0f, 4.0f); 92 Line2D l2 = new Line2D.Float (1.0f, 2.0f, 3.0f, 4.0f); 93 assertTrue(ShapeUtilities.equal(l1, l2)); 94 95 l1 = new Line2D.Float (4.0f, 3.0f, 2.0f, 1.0f); 96 assertFalse(ShapeUtilities.equal(l1, l2)); 97 l2 = new Line2D.Float (4.0f, 3.0f, 2.0f, 1.0f); 98 assertTrue(ShapeUtilities.equal(l1, l2)); 99 100 l1 = new Line2D.Double (4.0f, 3.0f, 2.0f, 1.0f); 101 assertTrue(ShapeUtilities.equal(l1, l2)); 102 103 } 104 105 108 public void testEqualShapes() { 109 110 Shape s1 = null; 112 Shape s2 = null; 113 assertTrue(ShapeUtilities.equal(s1, s2)); 114 115 s1 = new Line2D.Double (1.0, 2.0, 3.0, 4.0); 117 assertFalse(ShapeUtilities.equal(s1, s2)); 118 s2 = new Line2D.Double (1.0, 2.0, 3.0, 4.0); 119 assertTrue(ShapeUtilities.equal(s1, s2)); 120 assertFalse(s1.equals(s2)); 121 122 s1 = new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0); 124 assertFalse(ShapeUtilities.equal(s1, s2)); 125 s2 = new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0); 126 assertTrue(ShapeUtilities.equal(s1, s2)); 127 assertTrue(s1.equals(s2)); 129 s1 = new Ellipse2D.Double (1.0, 2.0, 3.0, 4.0); 131 assertFalse(ShapeUtilities.equal(s1, s2)); 132 s2 = new Ellipse2D.Double (1.0, 2.0, 3.0, 4.0); 133 assertTrue(ShapeUtilities.equal(s1, s2)); 134 assertFalse(s1.equals(s2)); 135 136 s1 = new Arc2D.Double (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, Arc2D.PIE); 138 assertFalse(ShapeUtilities.equal(s1, s2)); 139 s2 = new Arc2D.Double (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, Arc2D.PIE); 140 assertTrue(ShapeUtilities.equal(s1, s2)); 141 assertFalse(s1.equals(s2)); 142 143 Polygon p1 = new Polygon (new int[] {0, 1, 0}, new int[] {1, 0, 1}, 3); 145 Polygon p2 = new Polygon (new int[] {1, 1, 0}, new int[] {1, 0, 1}, 3); 146 s1 = p1; 147 s2 = p2; 148 assertFalse(ShapeUtilities.equal(s1, s2)); 149 p2 = new Polygon (new int[] {0, 1, 0}, new int[] {1, 0, 1}, 3); 150 s2 = p2; 151 assertTrue(ShapeUtilities.equal(s1, s2)); 152 153 GeneralPath g1 = new GeneralPath (); 155 g1.moveTo(1.0f, 2.0f); 156 g1.lineTo(3.0f, 4.0f); 157 g1.curveTo(5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f); 158 g1.quadTo(1.0f, 2.0f, 3.0f, 4.0f); 159 g1.closePath(); 160 s1 = g1; 161 assertFalse(ShapeUtilities.equal(s1, s2)); 162 GeneralPath g2 = new GeneralPath (); 163 g2.moveTo(1.0f, 2.0f); 164 g2.lineTo(3.0f, 4.0f); 165 g2.curveTo(5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f); 166 g2.quadTo(1.0f, 2.0f, 3.0f, 4.0f); 167 g2.closePath(); 168 s2 = g2; 169 assertTrue(ShapeUtilities.equal(s1, s2)); 170 assertFalse(s1.equals(s2)); 171 172 173 } 174 175 178 public void testIntersects () 179 { 180 final Rectangle2D r1 = new Rectangle2D.Float (0, 0, 100, 100); 181 final Rectangle2D r2 = new Rectangle2D.Float (0, 0, 100, 100); 182 assertTrue(ShapeUtilities.intersects(r1, r2)); 183 184 r1.setRect(100, 0, 100, 0); 185 assertTrue(ShapeUtilities.intersects(r1, r2)); 186 assertTrue(ShapeUtilities.intersects(r2, r1)); 187 188 r1.setRect(0, 0, 0, 0); 189 assertTrue(ShapeUtilities.intersects(r1, r2)); 190 assertTrue(ShapeUtilities.intersects(r2, r1)); 191 192 r1.setRect(50, 50, 10, 0); 193 assertTrue(ShapeUtilities.intersects(r1, r2)); 194 assertTrue(ShapeUtilities.intersects(r2, r1)); 195 } 196 } 197 | Popular Tags |