Revision: 1268
Author: heuermh
Date: Tue Dec 30 00:15:58 2014 UTC
Log: Issue 263 ; adding PPath.createPolyline methods
https://code.google.com/p/piccolo2d/source/detail?r=1268
Modified:
/piccolo2d.java/trunk/core/src/main/java/org/piccolo2d/nodes/PPath.java
/piccolo2d.java/trunk/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
=======================================
--- /piccolo2d.java/trunk/core/src/main/java/org/piccolo2d/nodes/PPath.java
Tue Dec 3 22:32:41 2013 UTC
+++ /piccolo2d.java/trunk/core/src/main/java/org/piccolo2d/nodes/PPath.java
Tue Dec 30 00:15:58 2014 UTC
@@ -37,6 +37,7 @@
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
@@ -283,14 +284,57 @@
return new PPath.Float(new Line2D.Float(x1, y1, x2, y2));
}
- /*
- need setPathToPolyline
+ /**
+ * Create and return a new path node with a shape defined by the
specified line segments in single
+ * precision floating point coordinates.
+ *
+ * @param xp array of x coordinates, must contain at least one x
coordinate
+ * @param yp array of y coordinates, must contain at least one y
coordinate
+ * @return a new path node with the a shape defined by the specified
line segments in single
+ * precision floating point coordinates
+ */
public static final PPath createPolyline(final float[] xp, final
float[] yp) {
+ if (xp.length < 1) {
+ throw new IllegalArgumentException("xp must contain at least
one x coordinate");
+ }
+ if (yp.length < 1) {
+ throw new IllegalArgumentException("yp must contain at least
one x coordinate");
+ }
+ if (xp.length != yp.length) {
+ throw new IllegalArgumentException("xp and yp must contain the
same number of coordinates");
+ }
+ Path2D.Float path = new Path2D.Float();
+ path.moveTo(xp[0], yp[0]);
+ for (int i = 1; i < xp.length; i++) {
+ path.lineTo(xp[i], yp[i]);
+ }
+ path.closePath();
+ return new PPath.Float(path);
}
+ /**
+ * Create and return a new path node with a shape defined by the
specified line segments in single
+ * precision floating point coordinates.
+ *
+ * @param points array of points, must not be null and must contain at
least one point
+ * @return a new path node with the a shape defined by the specified
line segments in single
+ * precision floating point coordinates
+ */
public static final PPath createPolyline(final Point2D.Float[] points)
{
+ if (points == null) {
+ throw new NullPointerException("points must not be null");
+ }
+ if (points.length < 1) {
+ throw new IllegalArgumentException("points must contain at
least one point");
+ }
+ Path2D.Float path = new Path2D.Float();
+ path.moveTo(points[0].getX(), points[0].getY());
+ for (int i = 1; i < points.length; i++) {
+ path.lineTo(points[i].getX(), points[i].getY());
+ }
+ path.closePath();
+ return new PPath.Float(path);
}
- */
/**
* Create and return a new path node with the specified quadratic
curve in single
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
Tue Dec 3 22:32:41 2013 UTC
+++
/piccolo2d.java/trunk/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
Tue Dec 30 00:15:58 2014 UTC
@@ -155,6 +155,62 @@
public void testCreateLineDouble() {
assertNotNull(PPath.createLine(0.0d, 0.0d, 50.0d, 100.0d));
}
+
+ public void testCreatePolylineFloatArraysEmpty() {
+ try {
+ PPath.createPolyline(new float[0], new float[0]);
+ fail("expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testCreatePolylineFloatArraysDifferentSizes() {
+ try {
+ PPath.createPolyline(new float[0], new float[] { 100.0f });
+ fail("expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testCreatePolylineFloatArraysDifferentSingle() {
+ assertNotNull(PPath.createPolyline(new float[] { 100.0f }, new
float[] { 100.0f }));
+ }
+
+ public void testCreatePolylineFloatArrays() {
+ assertNotNull(PPath.createPolyline(new float[] { 100.0f, 100.0f,
200.0f }, new float[] { 100.0f, 200.0f, 200.0f }));
+ }
+
+ public void testCreatePolylinePoint2DFloatArrayNull() {
+ try {
+ PPath.createPolyline((Point2D.Float[]) null);
+ fail("createPolyline(null) expected NullPointerException");
+ }
+ catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testCreatePolylinePoint2DFloatArrayEmpty() {
+ try {
+ PPath.createPolyline(new Point2D.Float[0]);
+ fail("expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testCreatePolylinePoint2DFloatArraySingle() {
+ assertNotNull(PPath.createPolyline(new Point2D.Float[] { new
Point2D.Float(100.0f, 100.0f) }));
+ }
+
+ public void testCreatePolylinePoint2DFloatArray() {
+ assertNotNull(PPath.createPolyline(new Point2D.Float[] { new
Point2D.Float(100.0f, 100.0f), new Point2D.Float(100.0f, 200.0f), new
Point2D.Float(200.0f, 200.0f) }));
+ }
public void testCreateQuadCurveDouble() {
assertNotNull(PPath.createQuadCurve(0.0d, 0.0d, 25.0d, 75.0d,
50.0d, 100.0d));
--
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
---
You received this message because you are subscribed to the Google Groups "Piccolo2D Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.