math.geom2d.curve
Class CurveSet2D<T extends Curve2D>

Package class diagram package CurveSet2D
java.lang.Object
  extended by math.geom2d.curve.CurveSet2D<T>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Curve2D, Shape2D
Direct Known Subclasses:
CurveArray2D

public class CurveSet2D<T extends Curve2D>
extends Object
implements Curve2D, Iterable<T>, Cloneable

A parameterized set of curves. A curve cannot be included twice in a CurveSet2D.

Note: this class will be transformed to an interface in a future version. Use the class CurveArray2D for implementations.

Author:
Legland
See Also:
Serialized Form

Field Summary
protected  ArrayList<T> curves
          The inner array of curves
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
CurveSet2D()
          Deprecated. use CurveArray2D instead
CurveSet2D(Collection<? extends T> curves)
          Deprecated. use CurveArray2D instead
CurveSet2D(int n)
          Deprecated. use CurveArray2D instead
CurveSet2D(T[] curves)
          Deprecated. use CurveArray2D instead
 
Method Summary
 void addCurve(T curve)
          Adds the curve to the curve set, if it does not already belongs to the set.
 void clearCurves()
          Clears the inner curve collection.
 CurveSet2D<? extends Curve2D> clip(Box2D box)
          Clips a curve, and return a CurveSet2D.
 CurveSet2D<? extends Curve2D> clone()
          Overrides Object declaration to ensure Curve2D implementation are cloned as Curve2D.
 boolean contains(double x, double y)
          Returns true if one of the curves contains the point
 boolean contains(Point2D p)
          Returns true if one of the curves contains the point
 boolean containsCurve(T curve)
          Checks if the curve set contains the given curve.
 void draw(Graphics2D g2)
          Draws the curve on the given Graphics2D object.
 boolean equals(Object obj)
          Returns true if obj is a CurveSet2D with the same number of curves, and such that each curve belongs to both objects.
protected static double fromUnitSegment(double t, double t0, double t1)
          Deprecated. use Curve2DUtils.fromUnitSegment() instead
 Shape getAsAWTShape()
           
 Box2D getBoundingBox()
          Returns bounding box for the CurveSet2D.
 T getChildCurve(double t)
          Returns the child curve corresponding to a given position.
 Collection<? extends ContinuousCurve2D> getContinuousCurves()
          Returns the collection of continuous curves which constitute this curve.
 T getCurve(int index)
          Returns the inner curve corresponding to the given index.
 int getCurveIndex(double t)
          Returns the index of the curve corresponding to a given position.
 int getCurveNumber()
          Returns the number of curves in the collection
 Collection<T> getCurves()
          Returns the collection of curves
 double getDistance(double x, double y)
          get the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e.
 double getDistance(Point2D p)
          get the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.
 T getFirstCurve()
          Returns the first curve of the collection if it exists, null otherwise.
 Point2D getFirstPoint()
          Get the first point of the curve.
 GeneralPath getGeneralPath()
           
 double getGlobalPosition(int i, double t)
          Converts a position on a curve (between t0 and t1 of the curve) to the position on the curve set (between 0 and 2*Nc-1).
 Collection<Point2D> getIntersections(LinearShape2D line)
          Returns the intersection points of the curve with the specified line.
 T getLastCurve()
          Returns the last curve of the collection if it exists, null otherwise.
 Point2D getLastPoint()
          Get the last point of the curve.
 double getLocalPosition(double t)
          Converts the position on the curve set, which is comprised between 0 and 2*Nc-1 with Nc being the number of curves, to the position on the curve which contains the position.
 Point2D getPoint(double t)
          Gets the point from a parametric representation of the curve.
 double getPosition(Point2D point)
          Get position of the point on the curve.
 Curve2D getReverseCurve()
          Returns the curve with same trace on the plane with parametrization in reverse order.
 Collection<Point2D> getSingularPoints()
          Computes the set of singular points as the set of singular points of each curve, plus the extremities of each curve.
 CurveSet2D<? extends Curve2D> getSubCurve(double t0, double t1)
          Return an instance of CurveSet2D.
 double getT0()
          Get value of parameter t for the first point of the curve.
 double getT1()
          Get value of parameter t for the last point of the curve.
 boolean isBounded()
          return true, if all curve pieces are bounded
 boolean isEmpty()
          Returns true if the CurveSet does not contain any curve.
 boolean isSingular(double pos)
          Checks if a point is singular.
 Iterator<T> iterator()
           
 double project(Point2D point)
          Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point.
 void removeCurve(T curve)
          Removes the specified curve from the curve set.
protected static double toUnitSegment(double t, double t0, double t1)
          Deprecated. use Curve2DUtils.toUnitSegment() instead
 CurveSet2D<? extends Curve2D> transform(AffineTransform2D trans)
          Transforms each curve, and build a new CurveSet2D with the set of transformed curves.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

curves

protected ArrayList<T extends Curve2D> curves
The inner array of curves

Constructor Detail

CurveSet2D

@Deprecated
public CurveSet2D()
Deprecated. use CurveArray2D instead

Empty constructor. Initializes an empty array of curves.


CurveSet2D

@Deprecated
public CurveSet2D(int n)
Deprecated. use CurveArray2D instead

Empty constructor. Initializes an empty array of curves, with a given size for allocating memory.


CurveSet2D

@Deprecated
public CurveSet2D(T[] curves)
Deprecated. use CurveArray2D instead

Constructor from an array of curves.

Parameters:
curves - the array of curves in the set

CurveSet2D

@Deprecated
public CurveSet2D(Collection<? extends T> curves)
Deprecated. use CurveArray2D instead

Constructor from a collection of curves. The curves are added to the inner collection of curves.

Parameters:
curves - the collection of curves to add to the set
Method Detail

toUnitSegment

@Deprecated
protected static final double toUnitSegment(double t,
                                                       double t0,
                                                       double t1)
Deprecated. use Curve2DUtils.toUnitSegment() instead

Mapping of the parameter t, relative to the local curve, into the interval [0 1], [0 1[, ]0 1], or ]0 1[, depending on the values of t0 and t1.

Parameters:
t - a value between t0 and t1
t0 - the lower bound of parameterization domain
t1 - the upper bound of parameterization domain
Returns:
a value between 0 and 1

fromUnitSegment

@Deprecated
protected static final double fromUnitSegment(double t,
                                                         double t0,
                                                         double t1)
Deprecated. use Curve2DUtils.fromUnitSegment() instead

Transforms the value t between 0 and 1 in a value comprised between t0 and t1.

Parameters:
t - a value between 0 and 1
t0 - the lower bound of parameterization domain
t1 - the upper bound of parameterization domain
Returns:
a value between t0 and t1

getLocalPosition

public double getLocalPosition(double t)
Converts the position on the curve set, which is comprised between 0 and 2*Nc-1 with Nc being the number of curves, to the position on the curve which contains the position. The result is comprised between the t0 and the t1 of the child curve.

Parameters:
t - the position on the curve set
Returns:
the position on the subcurve
See Also:
getGlobalPosition(int, double), getCurveIndex(double)

getGlobalPosition

public double getGlobalPosition(int i,
                                double t)
Converts a position on a curve (between t0 and t1 of the curve) to the position on the curve set (between 0 and 2*Nc-1).

Parameters:
i - the index of the curve to consider
t - the position on the curve
Returns:
the position on the curve set, between 0 and 2*Nc-1
See Also:
getLocalPosition(double), getCurveIndex(double)

getCurveIndex

public int getCurveIndex(double t)
Returns the index of the curve corresponding to a given position.

Parameters:
t - the position on the set of curves, between 0 and twice the number of curves minus 1
Returns:
the index of the curve which contains position t

addCurve

public void addCurve(T curve)
Adds the curve to the curve set, if it does not already belongs to the set.

Parameters:
curve - the curve to add

removeCurve

public void removeCurve(T curve)
Removes the specified curve from the curve set.

Parameters:
curve - the curve to remove

containsCurve

public boolean containsCurve(T curve)
Checks if the curve set contains the given curve.


clearCurves

public void clearCurves()
Clears the inner curve collection.


getCurves

public Collection<T> getCurves()
Returns the collection of curves

Returns:
the inner collection of curves

getCurve

public T getCurve(int index)
Returns the inner curve corresponding to the given index.

Parameters:
index - index of the curve
Returns:
the i-th inner curve
Since:
0.6.3

getChildCurve

public T getChildCurve(double t)
Returns the child curve corresponding to a given position.

Parameters:
t - the position on the set of curves, between 0 and twice the number of curves
Returns:
the curve corresponding to the position.
Since:
0.6.3

getFirstCurve

public T getFirstCurve()
Returns the first curve of the collection if it exists, null otherwise.

Returns:
the first curve of the collection

getLastCurve

public T getLastCurve()
Returns the last curve of the collection if it exists, null otherwise.

Returns:
the last curve of the collection

getCurveNumber

public int getCurveNumber()
Returns the number of curves in the collection

Returns:
the number of curves in the collection

isEmpty

public boolean isEmpty()
Returns true if the CurveSet does not contain any curve.

Specified by:
isEmpty in interface Shape2D
Returns:
true if the shape does not contain any point.

getIntersections

public Collection<Point2D> getIntersections(LinearShape2D line)
Description copied from interface: Curve2D
Returns the intersection points of the curve with the specified line. The length of the result array is the number of intersection points.

Specified by:
getIntersections in interface Curve2D

getT0

public double getT0()
Description copied from interface: Curve2D
Get value of parameter t for the first point of the curve. It can be -Infinity, in this case the piece of curve is not bounded.

Specified by:
getT0 in interface Curve2D

getT1

public double getT1()
Description copied from interface: Curve2D
Get value of parameter t for the last point of the curve. It can be +Infinity, in this case the piece of curve is not bounded.

Specified by:
getT1 in interface Curve2D

getPoint

public Point2D getPoint(double t)
Description copied from interface: Curve2D
Gets the point from a parametric representation of the curve. If the parameter lies outside the definition range, the parameter corresponding to the closest bound is used instead. This method can be used to draw an approximated outline of a curve, by selecting multiple values for t and drawing lines between them.

Specified by:
getPoint in interface Curve2D

getFirstPoint

public Point2D getFirstPoint()
Get the first point of the curve.

Specified by:
getFirstPoint in interface Curve2D
Returns:
the first point of the curve

getLastPoint

public Point2D getLastPoint()
Get the last point of the curve.

Specified by:
getLastPoint in interface Curve2D
Returns:
the last point of the curve.

getSingularPoints

public Collection<Point2D> getSingularPoints()
Computes the set of singular points as the set of singular points of each curve, plus the extremities of each curve. Each point is referenced only once.

Specified by:
getSingularPoints in interface Curve2D
Returns:
a collection of Point2D.

isSingular

public boolean isSingular(double pos)
Description copied from interface: Curve2D
Checks if a point is singular.

Specified by:
isSingular in interface Curve2D
Parameters:
pos - the position of the point on the curve
Returns:
true if the point at this location is singular

getPosition

public double getPosition(Point2D point)
Description copied from interface: Curve2D
Get position of the point on the curve. If the point does not belong to the curve, return Double.NaN.

Specified by:
getPosition in interface Curve2D
Parameters:
point - a point belonging to the curve
Returns:
the position of the point on the curve

project

public double project(Point2D point)
Description copied from interface: Curve2D
Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point. This function should always returns a valid value.

Specified by:
project in interface Curve2D
Parameters:
point - a point to project
Returns:
the position of the closest orthogonal projection

getReverseCurve

public Curve2D getReverseCurve()
Description copied from interface: Curve2D
Returns the curve with same trace on the plane with parametrization in reverse order.

Specified by:
getReverseCurve in interface Curve2D

getSubCurve

public CurveSet2D<? extends Curve2D> getSubCurve(double t0,
                                                 double t1)
Return an instance of CurveSet2D.

Specified by:
getSubCurve in interface Curve2D
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.

getDistance

public double getDistance(Point2D p)
Description copied from interface: Shape2D
get the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.

Specified by:
getDistance in interface Shape2D

getDistance

public double getDistance(double x,
                          double y)
Description copied from interface: Shape2D
get the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.

Specified by:
getDistance in interface Shape2D

isBounded

public boolean isBounded()
return true, if all curve pieces are bounded

Specified by:
isBounded in interface Shape2D

clip

public CurveSet2D<? extends Curve2D> clip(Box2D box)
Clips a curve, and return a CurveSet2D. If the curve is totally outside the box, return a CurveSet2D with 0 curves inside. If the curve is totally inside the box, return a CurveSet2D with only one curve, which is the original curve.

Specified by:
clip in interface Curve2D
Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

getBoundingBox

public Box2D getBoundingBox()
Returns bounding box for the CurveSet2D.

Specified by:
getBoundingBox in interface Shape2D
Returns:
the bounding box of the shape.

transform

public CurveSet2D<? extends Curve2D> transform(AffineTransform2D trans)
Transforms each curve, and build a new CurveSet2D with the set of transformed curves.

Specified by:
transform in interface Curve2D
Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

getContinuousCurves

public Collection<? extends ContinuousCurve2D> getContinuousCurves()
Description copied from interface: Curve2D
Returns the collection of continuous curves which constitute this curve.

Specified by:
getContinuousCurves in interface Curve2D
Returns:
a collection of continuous curves.

contains

public boolean contains(Point2D p)
Returns true if one of the curves contains the point

Specified by:
contains in interface Shape2D

contains

public boolean contains(double x,
                        double y)
Returns true if one of the curves contains the point

Specified by:
contains in interface Shape2D

getGeneralPath

public GeneralPath getGeneralPath()

getAsAWTShape

public Shape getAsAWTShape()
Specified by:
getAsAWTShape in interface Curve2D
Returns:
the shape corresponding to this curve

draw

public void draw(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
Parameters:
g2 - the graphics to draw the curve

equals

public boolean equals(Object obj)
Returns true if obj is a CurveSet2D with the same number of curves, and such that each curve belongs to both objects.

Overrides:
equals in class Object

clone

public CurveSet2D<? extends Curve2D> clone()
Description copied from interface: Curve2D
Overrides Object declaration to ensure Curve2D implementation are cloned as Curve2D.

Specified by:
clone in interface Curve2D
Overrides:
clone in class Object
Returns:
the cloned curve

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T extends Curve2D>


Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.