< prev index next >

test/java/awt/geom/Path2D/Path2DCopyConstructor.java

Print this page




 162 
 163     static Path2D addQuads(Path2D p2d) {
 164         for (int i = 0; i < 10; i++) {
 165             p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
 166         }
 167         return p2d;
 168     }
 169 
 170     static Path2D addMoveAndClose(Path2D p2d) {
 171         addMove(p2d);
 172         addClose(p2d);
 173         return p2d;
 174     }
 175 
 176     static Path2D addClose(Path2D p2d) {
 177         p2d.closePath();
 178         return p2d;
 179     }
 180 
 181     static void test(Path2D p2d, boolean isEmpty) {
 182         testEqual(new Path2D.Float(p2d), p2d);
 183         testEqual(new Path2D.Double(p2d), p2d);
 184         testEqual(new GeneralPath(p2d), p2d);
 185 
 186         testIterator(new Path2D.Float(p2d), p2d);
 187         testIterator(new Path2D.Double(p2d), p2d);
 188         testIterator((Path2D) p2d.clone(), p2d);
 189 
 190         testFlattening(new Path2D.Float(p2d), p2d);
 191         testFlattening(new Path2D.Double(p2d), p2d);
 192         testFlattening((Path2D) p2d.clone(), p2d);
 193 
 194         testAddMove(new Path2D.Float(p2d));
 195         testAddMove(new Path2D.Double(p2d));
 196         testAddMove((Path2D) p2d.clone());









































 197 
 198         // These should expect exception if empty
 199         testAddLine(new Path2D.Float(p2d), isEmpty);
 200         testAddLine(new Path2D.Double(p2d), isEmpty);
 201         testAddLine((Path2D) p2d.clone(), isEmpty);
 202 
 203         testAddQuad(new Path2D.Float(p2d), isEmpty);
 204         testAddQuad(new Path2D.Double(p2d), isEmpty);
 205         testAddQuad((Path2D) p2d.clone(), isEmpty);
 206 
 207         testAddCubic(new Path2D.Float(p2d), isEmpty);
 208         testAddCubic(new Path2D.Double(p2d), isEmpty);
 209         testAddCubic((Path2D) p2d.clone(), isEmpty);
 210 
 211         testAddClose(new Path2D.Float(p2d), isEmpty);
 212         testAddClose(new Path2D.Double(p2d), isEmpty);
 213         testAddClose((Path2D) p2d.clone(), isEmpty);
 214 
 215         testGetBounds(new Path2D.Float(p2d), p2d);
 216         testGetBounds(new Path2D.Double(p2d), p2d);
 217         testGetBounds((Path2D) p2d.clone(), p2d);
 218 
 219         testTransform(new Path2D.Float(p2d));
 220         testTransform(new Path2D.Double(p2d));
 221         testTransform((Path2D) p2d.clone());
 222 
 223         testIntersect(new Path2D.Float(p2d), p2d);
 224         testIntersect(new Path2D.Double(p2d), p2d);
 225         testIntersect((Path2D) p2d.clone(), p2d);
 226 
 227         testContains(new Path2D.Float(p2d), p2d);
 228         testContains(new Path2D.Double(p2d), p2d);
 229         testContains((Path2D) p2d.clone(), p2d);
 230 
 231         testGetCurrentPoint(new Path2D.Float(p2d), p2d);
 232         testGetCurrentPoint(new Path2D.Double(p2d), p2d);
 233         testGetCurrentPoint((Path2D) p2d.clone(), p2d);

















































































 234     }
 235 
 236     static void testEqual(Path2D pathA, Path2D pathB) {
 237         final PathIterator itA = pathA.getPathIterator(null);
 238         final PathIterator itB = pathB.getPathIterator(null);
 239 
 240         float[] coordsA = new float[6];
 241         float[] coordsB = new float[6];
 242 
 243         int n = 0;
 244         for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
 245             int typeA = itA.currentSegment(coordsA);
 246             int typeB = itB.currentSegment(coordsB);
 247 
 248             if (typeA != typeB) {
 249                 throw new IllegalStateException("Path-segment[" + n + "] "
 250                     + " type are not equals [" + typeA + "|" + typeB + "] !");
 251             }
 252             if (!equalsArray(coordsA, coordsB, getLength(typeA))) {
 253                 throw new IllegalStateException("Path-segment[" + n + "] coords"




 162 
 163     static Path2D addQuads(Path2D p2d) {
 164         for (int i = 0; i < 10; i++) {
 165             p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
 166         }
 167         return p2d;
 168     }
 169 
 170     static Path2D addMoveAndClose(Path2D p2d) {
 171         addMove(p2d);
 172         addClose(p2d);
 173         return p2d;
 174     }
 175 
 176     static Path2D addClose(Path2D p2d) {
 177         p2d.closePath();
 178         return p2d;
 179     }
 180 
 181     static void test(Path2D p2d, boolean isEmpty) {
 182         Path2D c;
 183         Path2D.Float pf;
 184         Path2D.Double pd;
 185         GeneralPath gp;
 186         
 187         pf = new Path2D.Float(p2d);
 188         testEqual(pf, p2d);
 189         testEqual(pf.trimToSize(), p2d);
 190         pd = new Path2D.Double(p2d);
 191         testEqual(pd, p2d);
 192         testEqual(pf.trimToSize(), p2d);
 193         c = (Path2D)p2d.clone();
 194         testEqual(c, p2d);
 195         testEqual(c.trimToSize(), p2d);
 196         gp = new GeneralPath(p2d);
 197         testEqual(gp, p2d);
 198         testEqual(gp.trimToSize(), p2d);
 199 
 200         pf = new Path2D.Float(p2d);
 201         testIterator(pf, p2d);
 202         testIterator(pf.trimToSize(), p2d);
 203         pd = new Path2D.Double(p2d);
 204         testIterator(pd, p2d);
 205         testIterator(pf.trimToSize(), p2d);
 206         c = (Path2D)p2d.clone();
 207         testIterator(c, p2d);
 208         testIterator(c.trimToSize(), p2d);
 209         gp = new GeneralPath(p2d);
 210         testIterator(gp, p2d);
 211         testIterator(gp.trimToSize(), p2d);
 212 
 213         pf = new Path2D.Float(p2d);
 214         testFlattening(pf, p2d);
 215         testFlattening(pf.trimToSize(), p2d);
 216         pd = new Path2D.Double(p2d);
 217         testFlattening(pd, p2d);
 218         testFlattening(pf.trimToSize(), p2d);
 219         c = (Path2D)p2d.clone();
 220         testFlattening(c, p2d);
 221         testFlattening(c.trimToSize(), p2d);
 222         gp = new GeneralPath(p2d);
 223         testFlattening(gp, p2d);
 224         testFlattening(gp.trimToSize(), p2d);
 225 
 226         pf = new Path2D.Float(p2d);
 227         testAddMove(pf);
 228         testAddMove(pf.trimToSize());
 229         pd = new Path2D.Double(p2d);
 230         testAddMove(pd);
 231         testAddMove(pf.trimToSize());
 232         c = (Path2D)p2d.clone();
 233         testAddMove(c);
 234         testAddMove(c.trimToSize());
 235         gp = new GeneralPath(p2d);
 236         testAddMove(gp);
 237         testAddMove(gp.trimToSize());
 238 
 239         // These should expect exception if empty
 240         pf = new Path2D.Float(p2d);
 241         testAddLine(pf, isEmpty);
 242         testAddLine(pf.trimToSize(), isEmpty);
 243         pd = new Path2D.Double(p2d);
 244         testAddLine(pd, isEmpty);
 245         testAddLine(pf.trimToSize(), isEmpty);
 246         c = (Path2D)p2d.clone();
 247         testAddLine(c, isEmpty);
 248         testAddLine(c.trimToSize(), isEmpty);
 249         gp = new GeneralPath(p2d);
 250         testAddLine(gp, isEmpty);
 251         testAddLine(gp.trimToSize(), isEmpty);
 252 
 253         pf = new Path2D.Float(p2d);
 254         testAddQuad(pf, isEmpty);
 255         testAddQuad(pf.trimToSize(), isEmpty);
 256         pd = new Path2D.Double(p2d);
 257         testAddQuad(pd, isEmpty);
 258         testAddQuad(pf.trimToSize(), isEmpty);
 259         c = (Path2D)p2d.clone();
 260         testAddQuad(c, isEmpty);
 261         testAddQuad(c.trimToSize(), isEmpty);
 262         gp = new GeneralPath(p2d);
 263         testAddQuad(gp, isEmpty);
 264         testAddQuad(gp.trimToSize(), isEmpty);
 265 
 266         pf = new Path2D.Float(p2d);
 267         testAddCubic(pf, isEmpty);
 268         testAddCubic(pf.trimToSize(), isEmpty);
 269         pd = new Path2D.Double(p2d);
 270         testAddCubic(pd, isEmpty);
 271         testAddCubic(pf.trimToSize(), isEmpty);
 272         c = (Path2D)p2d.clone();
 273         testAddCubic(c, isEmpty);
 274         testAddCubic(c.trimToSize(), isEmpty);
 275         gp = new GeneralPath(p2d);
 276         testAddCubic(gp, isEmpty);
 277         testAddCubic(gp.trimToSize(), isEmpty);
 278 
 279         pf = new Path2D.Float(p2d);
 280         testAddClose(pf, isEmpty);
 281         testAddClose(pf.trimToSize(), isEmpty);
 282         pd = new Path2D.Double(p2d);
 283         testAddClose(pd, isEmpty);
 284         testAddClose(pf.trimToSize(), isEmpty);
 285         c = (Path2D)p2d.clone();
 286         testAddClose(c, isEmpty);
 287         testAddClose(c.trimToSize(), isEmpty);
 288         gp = new GeneralPath(p2d);
 289         testAddClose(gp, isEmpty);
 290         testAddClose(gp.trimToSize(), isEmpty);
 291 
 292         pf = new Path2D.Float(p2d);
 293         testGetBounds(pf, p2d);
 294         testGetBounds(pf.trimToSize(), p2d);
 295         pd = new Path2D.Double(p2d);
 296         testGetBounds(pd, p2d);
 297         testGetBounds(pf.trimToSize(), p2d);
 298         c = (Path2D)p2d.clone();
 299         testGetBounds(c, p2d);
 300         testGetBounds(c.trimToSize(), p2d);
 301         gp = new GeneralPath(p2d);
 302         testGetBounds(gp, p2d);
 303         testGetBounds(gp.trimToSize(), p2d);
 304 
 305         pf = new Path2D.Float(p2d);
 306         testTransform(pf);
 307         testTransform(pf.trimToSize());
 308         pd = new Path2D.Double(p2d);
 309         testTransform(pd);
 310         testTransform(pf.trimToSize());
 311         c = (Path2D)p2d.clone();
 312         testTransform(c);
 313         testTransform(c.trimToSize());
 314         gp = new GeneralPath(p2d);
 315         testTransform(gp);
 316         testTransform(gp.trimToSize());
 317 
 318         pf = new Path2D.Float(p2d);
 319         testIntersect(pf, p2d);
 320         testIntersect(pf.trimToSize(), p2d);
 321         pd = new Path2D.Double(p2d);
 322         testIntersect(pd, p2d);
 323         testIntersect(pf.trimToSize(), p2d);
 324         c = (Path2D)p2d.clone();
 325         testIntersect(c, p2d);
 326         testIntersect(c.trimToSize(), p2d);
 327         gp = new GeneralPath(p2d);
 328         testIntersect(gp, p2d);
 329         testIntersect(gp.trimToSize(), p2d);
 330 
 331         pf = new Path2D.Float(p2d);
 332         testContains(pf, p2d);
 333         testContains(pf.trimToSize(), p2d);
 334         pd = new Path2D.Double(p2d);
 335         testContains(pd, p2d);
 336         testContains(pf.trimToSize(), p2d);
 337         c = (Path2D)p2d.clone();
 338         testContains(c, p2d);
 339         testContains(c.trimToSize(), p2d);
 340         gp = new GeneralPath(p2d);
 341         testContains(gp, p2d);
 342         testContains(gp.trimToSize(), p2d);
 343 
 344         pf = new Path2D.Float(p2d);
 345         testGetCurrentPoint(pf, p2d);
 346         testGetCurrentPoint(pf.trimToSize(), p2d);
 347         pd = new Path2D.Double(p2d);
 348         testGetCurrentPoint(pd, p2d);
 349         testGetCurrentPoint(pf.trimToSize(), p2d);
 350         c = (Path2D)p2d.clone();
 351         testGetCurrentPoint(c, p2d);
 352         testGetCurrentPoint(c.trimToSize(), p2d);
 353         gp = new GeneralPath(p2d);
 354         testGetCurrentPoint(gp, p2d);
 355         testGetCurrentPoint(gp.trimToSize(), p2d);
 356     }
 357 
 358     static void testEqual(Path2D pathA, Path2D pathB) {
 359         final PathIterator itA = pathA.getPathIterator(null);
 360         final PathIterator itB = pathB.getPathIterator(null);
 361 
 362         float[] coordsA = new float[6];
 363         float[] coordsB = new float[6];
 364 
 365         int n = 0;
 366         for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
 367             int typeA = itA.currentSegment(coordsA);
 368             int typeB = itB.currentSegment(coordsB);
 369 
 370             if (typeA != typeB) {
 371                 throw new IllegalStateException("Path-segment[" + n + "] "
 372                     + " type are not equals [" + typeA + "|" + typeB + "] !");
 373             }
 374             if (!equalsArray(coordsA, coordsB, getLength(typeA))) {
 375                 throw new IllegalStateException("Path-segment[" + n + "] coords"


< prev index next >