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

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

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

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

The k-th curve contains points with positions between 2*k and 2*k+1. This allows to differentiate extremities of contiguous curves. The points with positions t between 2*k+1 and 2*k+2 belong to the curve k if t<2*k+1.5, or to the curve k+1 if t>2*k+1.5

Author:
Legland
See Also:
Serialized Form

Field Summary
 
Fields inherited from class math.geom2d.curve.CurveSet2D
curves
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
CurveArray2D()
          Empty constructor.
CurveArray2D(Collection<? extends T> curves)
          Constructor from a collection of curves.
CurveArray2D(int n)
          Empty constructor.
CurveArray2D(T[] curves)
          Constructor from an array of curves.
 
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 CurveArray2D.
 CurveArray2D<? 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(Curve2D 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 CurveArray2D with the same number of curves, and such that each curve belongs to both objects.
 Shape getAsAWTShape()
           
 Box2D getBoundingBox()
          Returns bounding box for the CurveArray2D.
 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. fillable) shape.
 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).
 T getChildCurve(double t)
          Returns the child curve corresponding to a given position.
 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 CurveArray2D.
 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.
 CurveArray2D<? extends Curve2D> transform(AffineTransform2D trans)
          Transforms each curve, and build a new CurveArray2D with the set of transformed curves.
 
Methods inherited from class math.geom2d.curve.CurveSet2D
fromUnitSegment, toUnitSegment
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CurveArray2D

public CurveArray2D()
Empty constructor. Initializes an empty array of curves.


CurveArray2D

public CurveArray2D(int n)
Empty constructor. Initializes an empty array of curves, with a given size for allocating memory.


CurveArray2D

public CurveArray2D(T[] curves)
Constructor from an array of curves.

Parameters:
curves - the array of curves in the set

CurveArray2D

public CurveArray2D(Collection<? extends T> curves)
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

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.

Overrides:
getLocalPosition in class CurveSet2D<T extends Curve2D>
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).

Overrides:
getGlobalPosition in class CurveSet2D<T extends Curve2D>
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.

Overrides:
getCurveIndex in class CurveSet2D<T extends Curve2D>
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.

Overrides:
addCurve in class CurveSet2D<T extends Curve2D>
Parameters:
curve - the curve to add

removeCurve

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

Overrides:
removeCurve in class CurveSet2D<T extends Curve2D>
Parameters:
curve - the curve to remove

containsCurve

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

Overrides:
containsCurve in class CurveSet2D<T extends Curve2D>

clearCurves

public void clearCurves()
Clears the inner curve collection.

Overrides:
clearCurves in class CurveSet2D<T extends Curve2D>

getCurves

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

Overrides:
getCurves in class CurveSet2D<T extends Curve2D>
Returns:
the inner collection of curves

getCurve

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

Overrides:
getCurve in class CurveSet2D<T extends Curve2D>
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.

Overrides:
getChildCurve in class CurveSet2D<T extends Curve2D>
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.

Overrides:
getFirstCurve in class CurveSet2D<T extends Curve2D>
Returns:
the first curve of the collection

getLastCurve

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

Overrides:
getLastCurve in class CurveSet2D<T extends Curve2D>
Returns:
the last curve of the collection

getCurveNumber

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

Overrides:
getCurveNumber in class CurveSet2D<T extends Curve2D>
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
Overrides:
isEmpty in class CurveSet2D<T extends Curve2D>
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
Overrides:
getIntersections in class CurveSet2D<T extends 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
Overrides:
getT0 in class CurveSet2D<T extends 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
Overrides:
getT1 in class CurveSet2D<T extends 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
Overrides:
getPoint in class CurveSet2D<T extends Curve2D>

getFirstPoint

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

Specified by:
getFirstPoint in interface Curve2D
Overrides:
getFirstPoint in class CurveSet2D<T extends 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
Overrides:
getLastPoint in class CurveSet2D<T extends 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
Overrides:
getSingularPoints in class CurveSet2D<T extends 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
Overrides:
isSingular in class CurveSet2D<T extends 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
Overrides:
getPosition in class CurveSet2D<T extends 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
Overrides:
project in class CurveSet2D<T extends 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
Overrides:
getReverseCurve in class CurveSet2D<T extends Curve2D>

getSubCurve

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

Specified by:
getSubCurve in interface Curve2D
Overrides:
getSubCurve in class CurveSet2D<T extends 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
Overrides:
getDistance in class CurveSet2D<T extends Curve2D>

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
Overrides:
getDistance in class CurveSet2D<T extends Curve2D>

isBounded

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

Specified by:
isBounded in interface Shape2D
Overrides:
isBounded in class CurveSet2D<T extends Curve2D>

clip

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

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

getBoundingBox

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

Specified by:
getBoundingBox in interface Shape2D
Overrides:
getBoundingBox in class CurveSet2D<T extends Curve2D>
Returns:
the bounding box of the shape.

transform

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

Specified by:
transform in interface Curve2D
Specified by:
transform in interface Shape2D
Overrides:
transform in class CurveSet2D<T extends Curve2D>
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
Overrides:
getContinuousCurves in class CurveSet2D<T extends 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
Overrides:
contains in class CurveSet2D<T extends Curve2D>

contains

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

Specified by:
contains in interface Shape2D
Overrides:
contains in class CurveSet2D<T extends Curve2D>

getGeneralPath

public GeneralPath getGeneralPath()
Overrides:
getGeneralPath in class CurveSet2D<T extends Curve2D>

getAsAWTShape

public Shape getAsAWTShape()
Specified by:
getAsAWTShape in interface Curve2D
Overrides:
getAsAWTShape in class CurveSet2D<T extends 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
Overrides:
draw in class CurveSet2D<T extends Curve2D>
Parameters:
g2 - the graphics to draw the curve

equals

public boolean equals(Object obj)
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 CurveSet2D<T extends Curve2D>

clone

public CurveArray2D<? 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 CurveSet2D<T extends Curve2D>
Returns:
the cloned curve

iterator

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


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