math.geom2d.curve
Class PolyCurve2D<T extends ContinuousCurve2D>

java.lang.Object
  extended by math.geom2d.curve.CurveArray2D<T>
      extended by math.geom2d.curve.PolyCurve2D<T>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<T>, ContinuousCurve2D, Curve2D, CurveSet2D<T>, GeometricObject2D, Shape2D, ShapeSet2D<T>
Direct Known Subclasses:
PolyCubicBezierCurve2D, PolyOrientedCurve2D

public class PolyCurve2D<T extends ContinuousCurve2D>
extends CurveArray2D<T>
implements ContinuousCurve2D

A PolyCurve2D is a set of piecewise smooth curve arcs, such that the end of a curve is the beginning of the next curve, and such that they do not intersect nor self-intersect.

Author:
dlegland

Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
PolyCurve2D()
          Empty constructor.
PolyCurve2D(java.util.Collection<? extends T> curves)
          Creates a new PolyCurve2D from the specified collection of curves.
PolyCurve2D(java.util.Collection<? extends T> curves, boolean closed)
          Creates a new PolyCurve2D from the specified collection of curves.
PolyCurve2D(int n)
          Constructor that reserves space for the specified number of inner curves.
PolyCurve2D(T... curves)
          Creates a new PolyCurve2D from the specified list of curves.
PolyCurve2D(T[] curves, boolean closed)
          Creates a new closed PolyCurve2D from the specified list of curves.
 
Method Summary
 java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
          Append the path of the curve to the given path.
 Polyline2D asPolyline(int n)
          Converts this PolyCurve2D into a polyline with the given number of edges.
 CurveSet2D<? extends ContinuousCurve2D> clip(Box2D box)
          Clip the PolyCurve2D by a box.
 java.util.Collection<? extends PolyCurve2D<?>> continuousCurves()
          Returns a collection of PolyCurve2D that contains only this instance.
static
<T extends ContinuousCurve2D>
PolyCurve2D<T>
create(java.util.Collection<T> curves)
          Static factory for creating a new PolyCurve2D from a collection of curves.
static
<T extends ContinuousCurve2D>
PolyCurve2D<T>
create(java.util.Collection<T> curves, boolean closed)
          Static factory for creating a new PolyCurve2D from a collection of curves and a flag indicating if the curve is closed or not.
static
<T extends ContinuousCurve2D>
PolyCurve2D<T>
create(T... curves)
          Static factory for creating a new PolyCurve2D from an array of curves.
static
<T extends ContinuousCurve2D>
PolyCurve2D<T>
create(T[] curves, boolean closed)
          Static factory for creating a new PolyCurve2D from an array of curves and a flag indicating if the curve is closed or not.
static
<T extends ContinuousCurve2D>
PolyCurve2D<T>
createClosed(T... curves)
          Static factory for creating a new closed PolyCurve2D from an array of curves.
 double curvature(double t)
          Computes the curvature at the given position.
 void draw(java.awt.Graphics2D g2)
          Draws the curve on the given Graphics2D object.
 boolean equals(java.lang.Object obj)
          Returns true if obj is a CurveArray2D with the same number of curves, and such that each curve belongs to both objects.
 java.awt.geom.GeneralPath getGeneralPath()
           
 boolean isClosed()
          Returns true if the PolyCurve2D is closed.
 Vector2D leftTangent(double t)
          Computes the left tangent at the given position.
 PolyCurve2D<? extends ContinuousCurve2D> reverse()
          Returns the reverse curve of this PolyCurve2D.
 Vector2D rightTangent(double t)
          Computes the right tangent at the given position.
 void setClosed(boolean b)
          Toggle the 'closed' flag of this polycurve.
 java.util.Collection<? extends SmoothCurve2D> smoothPieces()
          Returns a collection containing only instances of SmoothCurve2D.
 PolyCurve2D<? extends ContinuousCurve2D> subCurve(double t0, double t1)
          Returns an instance of PolyCurve2D.
 PolyCurve2D<? extends ContinuousCurve2D> transform(AffineTransform2D trans)
          Transforms each smooth piece in this PolyCurve2D and returns a new instance of PolyCurve2D.
 
Methods inherited from class math.geom2d.curve.CurveArray2D
add, add, almostEquals, asAwtShape, boundingBox, childCurve, clear, clone, contains, contains, contains, curveIndex, curves, distance, distance, firstCurve, firstPoint, get, getT0, getT1, globalPosition, indexOf, intersections, isBounded, isEmpty, isSingular, iterator, lastCurve, lastPoint, localPosition, point, position, project, remove, remove, singularPoints, size, t0, t1, vertices
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface math.geom2d.curve.Curve2D
asAwtShape, clone, firstPoint, getT0, getT1, intersections, isSingular, lastPoint, point, position, project, singularPoints, t0, t1, vertices
 
Methods inherited from interface math.geom2d.Shape2D
boundingBox, contains, contains, distance, distance, isBounded, isEmpty
 
Methods inherited from interface math.geom2d.GeometricObject2D
almostEquals
 

Constructor Detail

PolyCurve2D

public PolyCurve2D()
Empty constructor.


PolyCurve2D

public PolyCurve2D(int n)
Constructor that reserves space for the specified number of inner curves.


PolyCurve2D

public PolyCurve2D(T... curves)
Creates a new PolyCurve2D from the specified list of curves.

Parameters:
curves - the curves that constitutes this PolyCurve2D

PolyCurve2D

public PolyCurve2D(T[] curves,
                   boolean closed)
Creates a new closed PolyCurve2D from the specified list of curves.

Parameters:
curves - the curves that constitutes this PolyCurve2D

PolyCurve2D

public PolyCurve2D(java.util.Collection<? extends T> curves)
Creates a new PolyCurve2D from the specified collection of curves.

Parameters:
curves - the curves that constitutes this PolyCurve2D

PolyCurve2D

public PolyCurve2D(java.util.Collection<? extends T> curves,
                   boolean closed)
Creates a new PolyCurve2D from the specified collection of curves.

Parameters:
curves - the curves that constitutes this PolyCurve2D
Method Detail

create

public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(java.util.Collection<T> curves)
Static factory for creating a new PolyCurve2D from a collection of curves.

Since:
0.8.1

create

public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(T... curves)
Static factory for creating a new PolyCurve2D from an array of curves.

Since:
0.8.1

createClosed

public static <T extends ContinuousCurve2D> PolyCurve2D<T> createClosed(T... curves)
Static factory for creating a new closed PolyCurve2D from an array of curves.

Since:
0.10.0

create

public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(java.util.Collection<T> curves,
                                                                  boolean closed)
Static factory for creating a new PolyCurve2D from a collection of curves and a flag indicating if the curve is closed or not.

Since:
0.9.0

create

public static <T extends ContinuousCurve2D> PolyCurve2D<T> create(T[] curves,
                                                                  boolean closed)
Static factory for creating a new PolyCurve2D from an array of curves and a flag indicating if the curve is closed or not.

Since:
0.9.0

setClosed

public void setClosed(boolean b)
Toggle the 'closed' flag of this polycurve.


leftTangent

public Vector2D leftTangent(double t)
Description copied from interface: ContinuousCurve2D
Computes the left tangent at the given position. If the curve is smooth at position t, the result is the same as the tangent computed for the corresponding smooth curve, and is equal to the result of rightTangent(double). If the position t corresponds to a singular point, the tangent of the smooth portion before t is computed.

Specified by:
leftTangent in interface ContinuousCurve2D
Parameters:
t - the position on the curve
Returns:
the left tangent vector at the curve for position t

rightTangent

public Vector2D rightTangent(double t)
Description copied from interface: ContinuousCurve2D
Computes the right tangent at the given position. If the curve is smooth at position t, the result is the same as the tangent computed for the corresponding smooth curve, and is equal to the result of leftTangent(double). If the position t corresponds to a singular point, the tangent of the smooth portion after t is computed.

Specified by:
rightTangent in interface ContinuousCurve2D
Parameters:
t - the position on the curve
Returns:
the right tangent vector at the curve for position t

curvature

public double curvature(double t)
Description copied from interface: ContinuousCurve2D
Computes the curvature at the given position. The curvature is finite for positions t that correspond to smooth parts, and is infinite for singular points.

Specified by:
curvature in interface ContinuousCurve2D
Parameters:
t - the position on the curve
Returns:
the curvature of the curve for position t

isClosed

public boolean isClosed()
Returns true if the PolyCurve2D is closed.

Specified by:
isClosed in interface ContinuousCurve2D

asPolyline

public Polyline2D asPolyline(int n)
Converts this PolyCurve2D into a polyline with the given number of edges.

Specified by:
asPolyline in interface ContinuousCurve2D
Parameters:
n - the number of edges of the result polyline
Returns:
a polyline with n line segments.
See Also:
Polyline2D

smoothPieces

public java.util.Collection<? extends SmoothCurve2D> smoothPieces()
Returns a collection containing only instances of SmoothCurve2D.

Specified by:
smoothPieces in interface ContinuousCurve2D
Returns:
a collection of SmoothCurve2D

continuousCurves

public java.util.Collection<? extends PolyCurve2D<?>> continuousCurves()
Returns a collection of PolyCurve2D that contains only this instance.

Specified by:
continuousCurves in interface Curve2D
Overrides:
continuousCurves in class CurveArray2D<T extends ContinuousCurve2D>
Returns:
a collection of continuous curves.

reverse

public PolyCurve2D<? extends ContinuousCurve2D> reverse()
Returns the reverse curve of this PolyCurve2D.

Specified by:
reverse in interface ContinuousCurve2D
Specified by:
reverse in interface Curve2D
Overrides:
reverse in class CurveArray2D<T extends ContinuousCurve2D>

subCurve

public PolyCurve2D<? extends ContinuousCurve2D> subCurve(double t0,
                                                         double t1)
Returns an instance of PolyCurve2D. If t0>t1 and curve is not closed, return a PolyCurve2D without curves inside.

Specified by:
subCurve in interface ContinuousCurve2D
Specified by:
subCurve in interface Curve2D
Overrides:
subCurve in class CurveArray2D<T extends ContinuousCurve2D>
Parameters:
t0 - position of the start of the sub-curve
t1 - position of the end of the sub-curve
Returns:
the portion of original curve comprised between t0 and t1.

clip

public CurveSet2D<? extends ContinuousCurve2D> clip(Box2D box)
Clip the PolyCurve2D by a box. The result is an instance of CurveSet2D, which contains only instances of ContinuousCurve2D. If the PolyCurve2D is not clipped, the result is an instance of CurveSet2D which contains 0 curves.

Specified by:
clip in interface ContinuousCurve2D
Specified by:
clip in interface Curve2D
Specified by:
clip in interface Shape2D
Overrides:
clip in class CurveArray2D<T extends ContinuousCurve2D>
Parameters:
box - the clipping box
Returns:
the clipped shape

transform

public PolyCurve2D<? extends ContinuousCurve2D> transform(AffineTransform2D trans)
Transforms each smooth piece in this PolyCurve2D and returns a new instance of PolyCurve2D.

Specified by:
transform in interface ContinuousCurve2D
Specified by:
transform in interface Curve2D
Specified by:
transform in interface CurveSet2D<T extends ContinuousCurve2D>
Specified by:
transform in interface Shape2D
Overrides:
transform in class CurveArray2D<T extends ContinuousCurve2D>
Parameters:
trans - an affine transform
Returns:
the transformed shape

appendPath

public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
Description copied from interface: ContinuousCurve2D
Append the path of the curve to the given path.

Specified by:
appendPath in interface ContinuousCurve2D
Parameters:
path - a path to modify
Returns:
the modified path

getGeneralPath

public java.awt.geom.GeneralPath getGeneralPath()
Overrides:
getGeneralPath in class CurveArray2D<T extends ContinuousCurve2D>

draw

public void draw(java.awt.Graphics2D g2)
Description copied from interface: Curve2D
Draws the curve on the given Graphics2D object.

Specified by:
draw in interface Curve2D
Specified by:
draw in interface Shape2D
Overrides:
draw in class CurveArray2D<T extends ContinuousCurve2D>
Parameters:
g2 - the graphics to draw the curve in

equals

public boolean equals(java.lang.Object obj)
Description copied from class: CurveArray2D
Returns true if obj is a CurveArray2D with the same number of curves, and such that each curve belongs to both objects.

Overrides:
equals in class CurveArray2D<T extends ContinuousCurve2D>