Revision: 1032
Author: heuermh
Date: Mon Aug  2 09:49:24 2010
Log: tightening API a bit, increasing test coverage
http://code.google.com/p/piccolo2d/source/detail?r=1032

Modified:
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PShape.java /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathTest.java

=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java Fri Jul 23 13:43:12 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java Mon Aug 2 09:49:24 2010
@@ -36,7 +36,7 @@
 /**
  * Area node.
  */
-public class PArea extends PShape
+public final class PArea extends PShape
 {
     private transient Area area;

=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java Fri Jul 23 13:43:12 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java Mon Aug 2 09:49:24 2010
@@ -50,10 +50,7 @@

     // todo: ctr with stroke?

-    PPath(final Path2D path) {
-        if (path == null) {
-            throw new IllegalArgumentException("path must not be null");
-        }
+    private PPath(final Path2D path) {
         this.path = (Path2D) path.clone();
         // todo:
// not sure why this call is required for this class, it is not present in original PPath
@@ -61,7 +58,7 @@
     }


-    public static class Float extends PPath {
+    public static final class Float extends PPath {
         public Float() {
             super(new Path2D.Float());
         }
@@ -73,7 +70,7 @@
         }
     }

-    public static class Double extends PPath {
+    public static final class Double extends PPath {
         public Double() {
             super(new Path2D.Double());
         }
@@ -86,111 +83,111 @@
     }


- public static PPath createArc(final float x, final float y, final float width, final float height, final float start, final float extent, final int type) { + public static final PPath createArc(final float x, final float y, final float width, final float height, final float start, final float extent, final int type) { return new PPath.Float(new Arc2D.Float(x, y, width, height, start, extent, type));
     }

- public static PPath createCubicCurve(final float x1, final float y1, final float ctrlx1, final float ctrly1, final float ctrlx2, final float ctrly2, final float x2, final float y2) { + public static final PPath createCubicCurve(final float x1, final float y1, final float ctrlx1, final float ctrly1, final float ctrlx2, final float ctrly2, final float x2, final float y2) { return new PPath.Float(new CubicCurve2D.Float(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
     }

- public static PPath createEllipse(final float x, final float y, final float width, final float height) { + public static final PPath createEllipse(final float x, final float y, final float width, final float height) {
         return new PPath.Float(new Ellipse2D.Float(x, y, width, height));
     }

- public static PPath createLine(final float x1, final float y1, final float x2, final float y2) { + public static final PPath createLine(final float x1, final float y1, final float x2, final float y2) {
         return new PPath.Float(new Line2D.Float(x1, y1, x2, y2));
     }

     /*
       need setPathToPolyline
- public static PPath createPolyline(final float[] xp, final float[] yp) { + public static final PPath createPolyline(final float[] xp, final float[] yp) {
     }

-    public static PPath createPolyline(final Point2D.Float[] points) {
+ public static final PPath createPolyline(final Point2D.Float[] points) {
     }
     */

- public static PPath createQuadCurve(final float x1, final float y1, final float ctrlx, final float ctrly, final float x2, final float y2) { + public static final PPath createQuadCurve(final float x1, final float y1, final float ctrlx, final float ctrly, final float x2, final float y2) { return new PPath.Float(new QuadCurve2D.Float(x1, y1, ctrlx, ctrly, x2, y2));
     }

- public static PPath createRectangle(final float x, final float y, final float width, final float height) { + public static final PPath createRectangle(final float x, final float y, final float width, final float height) {
         return new PPath.Float(new Rectangle2D.Float(x, y, width, height));
     }

- public static PPath createRoundRectangle(final float x, final float y, final float width, final float height, final float arcWidth, final float arcHeight) { + public static final PPath createRoundRectangle(final float x, final float y, final float width, final float height, final float arcWidth, final float arcHeight) { return new PPath.Float(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
     }

- public static PPath createArc(final double x, final double y, final double width, final double height, final double start, final double extent, final int type) { + public static final PPath createArc(final double x, final double y, final double width, final double height, final double start, final double extent, final int type) { return new PPath.Double(new Arc2D.Double(x, y, width, height, start, extent, type));
     }

- public static PPath createCubicCurve(final double x1, final double y1, final double ctrlx1, final double ctrly1, final double ctrlx2, final double ctrly2, final double x2, final double y2) { + public static final PPath createCubicCurve(final double x1, final double y1, final double ctrlx1, final double ctrly1, final double ctrlx2, final double ctrly2, final double x2, final double y2) { return new PPath.Double(new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
     }

- public static PPath createEllipse(final double x, final double y, final double width, final double height) { + public static final PPath createEllipse(final double x, final double y, final double width, final double height) {
         return new PPath.Double(new Ellipse2D.Double(x, y, width, height));
     }

- public static PPath createLine(final double x1, final double y1, final double x2, final double y2) { + public static final PPath createLine(final double x1, final double y1, final double x2, final double y2) {
         return new PPath.Double(new Line2D.Double(x1, y1, x2, y2));
     }

     /*
- public static PPath createPolyline(final double[] xp, final double[] yp) { + public static final PPath createPolyline(final double[] xp, final double[] yp) {
     }

-    public static PPath createPolyline(final Point2D.Double[] points) {
+ public static final PPath createPolyline(final Point2D.Double[] points) {
     }
     */

- public static PPath createQuadCurve(final double x1, final double y1, final double ctrlx, final double ctrly, final double x2, final double y2) { + public static final PPath createQuadCurve(final double x1, final double y1, final double ctrlx, final double ctrly, final double x2, final double y2) { return new PPath.Double(new QuadCurve2D.Double(x1, y1, ctrlx, ctrly, x2, y2));
     }

- public static PPath createRectangle(final double x, final double y, final double width, final double height) { + public static final PPath createRectangle(final double x, final double y, final double width, final double height) { return new PPath.Double(new Rectangle2D.Double(x, y, width, height));
     }

- public static PPath createRoundRectangle(final double x, final double y, final double width, final double height, final double arcWidth, final double arcHeight) { + public static final PPath createRoundRectangle(final double x, final double y, final double width, final double height, final double arcWidth, final double arcHeight) { return new PPath.Double(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
     }


-    public void append(final Shape shape, final boolean connect) {
+    public final void append(final Shape shape, final boolean connect) {
         path.append(shape, connect);
         updateBoundsFromShape();
     }

- public void append(final PathIterator pathIterator, final boolean connect) { + public final void append(final PathIterator pathIterator, final boolean connect) {
         path.append(pathIterator, connect);
         updateBoundsFromShape();
     }

- public void curveTo(final double x1, final double y1, final double x2, final double y2, final double x3, final double y3) { + public final void curveTo(final double x1, final double y1, final double x2, final double y2, final double x3, final double y3) {
         path.curveTo(x1, y1, x2, y2, x3, y3);
         updateBoundsFromShape();
     }

-    public void lineTo(final double x, final double y) {
+    public final void lineTo(final double x, final double y) {
         path.lineTo(x, y);
         updateBoundsFromShape();
     }

-    public void moveTo(final double x, final double y) {
+    public final void moveTo(final double x, final double y) {
         path.moveTo(x, y);
         updateBoundsFromShape();
     }

- public void quadTo(final double x1, final double y1, final double x2, final double y2) { + public final void quadTo(final double x1, final double y1, final double x2, final double y2) {
         path.quadTo(x1, y1, x2, y2);
         updateBoundsFromShape();
     }

-    public void closePath() {
+    public final void closePath() {
         path.closePath();
         updateBoundsFromShape();
     }
@@ -199,12 +196,12 @@
     //    path property change events

     /** {...@inheritdoc} */
-    protected Shape getShape() {
+    protected final Shape getShape() {
         return path;
     }

     /** {...@inheritdoc} */
-    protected void transform(final AffineTransform transform) {
+    protected final void transform(final AffineTransform transform) {
         path.transform(transform);
     }
 }
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PShape.java Fri Jul 23 11:55:49 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PShape.java Mon Aug 2 09:49:24 2010
@@ -78,13 +78,8 @@
     }

     protected final void updateBoundsFromShape() {
-        if (getShape() == null) {
-            resetBounds();
-        }
-        else {
-            final Rectangle2D b = getBoundsWithStroke();
-            setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
-        }
+        final Rectangle2D b = getBoundsWithStroke();
+        setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
     }

     protected final Rectangle2D getBoundsWithStroke() {
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathTest.java Fri Jul 23 11:55:49 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathTest.java Mon Aug 2 09:49:24 2010
@@ -29,8 +29,14 @@
 package org.piccolo2d.nodes;

 import java.awt.Color;
+import java.awt.Shape;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Arc2D;
+import java.awt.geom.PathIterator;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -40,7 +46,9 @@

 import org.piccolo2d.MockPropertyChangeListener;
 import org.piccolo2d.PiccoloAsserts;
+
 import org.piccolo2d.nodes.PPath;
+
 import org.piccolo2d.util.PBounds;
 import org.piccolo2d.util.PObjectOutputStream;

@@ -51,6 +59,9 @@
  */
 public class PPathTest extends TestCase {

+    private static final double TOLERANCE = 0.0001d;
+    private static final double LOW_TOLERANCE = 1.0d;
+
     private MockPropertyChangeListener mockListener;

     public void setUp() {
@@ -162,7 +173,7 @@
         assertEquals(Color.RED, path.getStrokePaint());
     }

-    // move these to PShape test, add stroke
+    // todo:  move these to PShape test, add stroke
     public void testSetStrokeFiresPropertyChangeEvent() {
         final PPath path = new PPath.Double();
         path.addPropertyChangeListener("strokePaint", mockListener);
@@ -177,4 +188,140 @@
         assertEquals(1, mockListener.getPropertyChangeCount());
     }

-}
+    public void testCreateArcFloat() {
+ assertNotNull(PPath.createArc(0.0f, 0.0f, 50.0f, 100.0f, 25.0f, 75.0f, Arc2D.OPEN));
+    }
+
+    public void testCreateCubicCurveFloat() {
+ assertNotNull(PPath.createCubicCurve(0.0f, 0.0f, 25.0f, 75.0f, 75.0f, 25.0f, 50.0f, 100.0f));
+    }
+
+    public void testCreateEllipseFloat() {
+        assertNotNull(PPath.createEllipse(0.0f, 0.0f, 50.0f, 100.0f));
+    }
+
+    public void testCreateLineFloat() {
+        assertNotNull(PPath.createLine(0.0f, 0.0f, 50.0f, 100.0f));
+    }
+
+    public void testCreateQuadCurveFloat() {
+ assertNotNull(PPath.createQuadCurve(0.0f, 0.0f, 25.0f, 75.0f, 50.0f, 100.0f));
+    }
+
+    public void testCreateRectangleFloat() {
+        assertNotNull(PPath.createRectangle(0.0f, 0.0f, 50.0f, 100.0f));
+    }
+
+    public void testCreateRoundRectangleFloat() {
+ assertNotNull(PPath.createRoundRectangle(0.0f, 0.0f, 50.0f, 100.0f, 4.0f, 8.0f));
+    }
+
+    public void testCreateArcDouble() {
+ assertNotNull(PPath.createArc(0.0d, 0.0d, 50.0d, 100.0d, 25.0d, 75.0d, Arc2D.OPEN));
+    }
+
+    public void testCreateCubicCurveDouble() {
+ assertNotNull(PPath.createCubicCurve(0.0d, 0.0d, 25.0d, 75.0d, 75.0d, 25.0d, 50.0d, 100.0d));
+    }
+
+    public void testCreateEllipseDouble() {
+        assertNotNull(PPath.createEllipse(0.0d, 0.0d, 50.0d, 100.0d));
+    }
+
+    public void testCreateLineDouble() {
+        assertNotNull(PPath.createLine(0.0d, 0.0d, 50.0d, 100.0d));
+    }
+
+    public void testCreateQuadCurveDouble() {
+ assertNotNull(PPath.createQuadCurve(0.0d, 0.0d, 25.0d, 75.0d, 50.0d, 100.0d));
+    }
+
+    public void testCreateRectangleDouble() {
+        assertNotNull(PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d));
+    }
+
+    public void testCreateRoundRectangleDouble() {
+ assertNotNull(PPath.createRoundRectangle(0.0d, 0.0d, 50.0d, 100.0d, 4.0d, 8.0d));
+    }
+
+    public void testAppendShape() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d, 100.0d);
+        path.append(rect, true);
+        // todo:  shouldn't this be width + 2 * strokeWidth?
+        assertEquals(101.0d, path.getWidth(), TOLERANCE);
+        assertEquals(201.0d, path.getHeight(), TOLERANCE);
+    }
+
+    public void testAppendShapeNullArgument() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        try {
+            path.append((Shape) null, true);
+ fail("append((Shape) null, true) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testAppendPathIterator() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d, 100.0d); + PathIterator pathIterator = rect.getPathIterator(new AffineTransform());
+        path.append(pathIterator, true);
+        assertEquals(101.0d, path.getWidth(), TOLERANCE);
+        assertEquals(201.0d, path.getHeight(), TOLERANCE);
+    }
+
+    public void testAppendPathIteratorNullArgument() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        try {
+            path.append((PathIterator) null, true);
+ fail("append((PathIterator) null, true) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testCurveTo() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        path.curveTo(70.0d, 140.0d, 80.0d, 140.0d, 100.0d, 200.0d);
+        assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
+        assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
+    }
+
+    public void testLineTo() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        path.lineTo(100.0d, 200.0d);
+        assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
+        assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
+    }
+
+    public void testMoveTo() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        path.moveTo(100.0d, 200.0d);
+        assertEquals(51.0d, path.getWidth(), TOLERANCE);
+        assertEquals(101.0d, path.getHeight(), TOLERANCE);
+    }
+
+    public void testQuadTo() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        path.quadTo(70.0d, 140.0d, 100.0d, 200.0d);
+        assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
+        assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
+    }
+
+    public void testClosePath() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        path.lineTo(100.0d, 200.0d);
+        path.closePath();
+    }
+
+    public void testClosePathAlreadyClosed() {
+        PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+        path.lineTo(100.0d, 200.0d);
+        path.closePath();
+        path.closePath();
+    }
+}

--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to