math.geom2d.curve
Class CurveArray2D<T extends Curve2D>
- java.lang.Object
-
- math.geom2d.curve.CurveArray2D<T>
-
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Iterable<T>, Curve2D, CurveSet2D<T>, GeometricObject2D, Shape2D, ShapeSet2D<T>
- Direct Known Subclasses:
- CirculinearCurveArray2D, ContourArray2D, PolyCurve2D
public class CurveArray2D<T extends Curve2D> extends java.lang.Object implements CurveSet2D<T>, java.lang.Iterable<T>, java.lang.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
-
-
Constructor Summary
Constructors Constructor and Description CurveArray2D()Empty constructor.CurveArray2D(java.util.Collection<? extends T> curves)Constructor from a collection of curves.CurveArray2D(CurveSet2D<? extends T> set)CurveArray2D(int n)Empty constructor.CurveArray2D(T... curves)Constructor from an array of curves.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidadd(int index, T curve)Inserts the specified shape at the specified position in this set (optional operation).booleanadd(T curve)Adds the curve to the curve set, if it does not already belongs to the set.booleanalmostEquals(GeometricObject2D obj, double eps)Checks if the two objects are similar up to a given threshold value.java.awt.ShapeasAwtShape()Box2DboundingBox()Returns bounding box for the CurveArray2D.TchildCurve(double t)Returns the child curve corresponding to a given position.voidclear()Clears the inner curve collection.CurveSet2D<? extends Curve2D>clip(Box2D box)Clips a curve, and return a CurveArray2D.CurveArray2D<? extends Curve2D>clone()Deprecated.use copy constructor instead (0.11.2)booleancontains(double x, double y)Returns true if one of the curves contains the pointbooleancontains(Point2D p)Returns true if one of the curves contains the pointbooleancontains(T curve)Checks if the curve set contains the given curve.java.util.Collection<? extends ContinuousCurve2D>continuousCurves()Returns the collection of continuous curves which constitute this curve.static <T extends Curve2D>
CurveArray2D<T>create(java.util.Collection<T> curves)Static factory for creating a new CurveArray2D from a collection of curves.static <T extends Curve2D>
CurveArray2D<T>create(T... curves)Static factory for creating a new CurveArray2D from an array of curves.intcurveIndex(double t)Returns the index of the curve corresponding to a given position.java.util.Collection<T>curves()Returns the collection of curvesdoubledistance(double x, double y)Returns 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.doubledistance(Point2D p)Returns 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.voiddraw(java.awt.Graphics2D g2)Draws the curve on the given Graphics2D object.booleanequals(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.TfirstCurve()Returns the first curve of the collection if it exists, null otherwise.Point2DfirstPoint()Returns the first point of the curve.Tget(int index)Returns the inner curve corresponding to the given index.java.awt.geom.GeneralPathgetGeneralPath()doublegetT0()Deprecated.replaced by t0() (since 0.11.1).doublegetT1()Deprecated.replaced by t1() (since 0.11.1).doubleglobalPosition(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).intindexOf(T curve)Returns index of the given curve within the inner array.java.util.Collection<Point2D>intersections(LinearShape2D line)Returns the intersection points of the curve with the specified line.booleanisBounded()return true, if all curve pieces are boundedbooleanisEmpty()Returns true if the CurveSet does not contain any curve.booleanisSingular(double pos)Checks if a point is singular.java.util.Iterator<T>iterator()TlastCurve()Returns the last curve of the collection if it exists, null otherwise.Point2DlastPoint()Returns the last point of the curve.doublelocalPosition(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.Point2Dpoint(double t)Returns the point located at the given position on the curve.doubleposition(Point2D point)Computes the position of the point on the curve.doubleproject(Point2D point)Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point.Tremove(int index)Removes the shape at the specified position in this set (optional operation).booleanremove(T curve)Removes the specified curve from the curve set.Curve2Dreverse()Returns the curve with same trace on the plane with parameterization in reverse order.java.util.Collection<Point2D>singularPoints()Computes the set of singular points as the set of singular points of each curve, plus the extremities of each curve.intsize()Returns the number of curves in the collectionCurveSet2D<? extends Curve2D>subCurve(double t0, double t1)Return an instance of CurveArray2D.doublet0()Returns 0.doublet1()Get value of parameter t for the last point of the curve.CurveArray2D<? extends Curve2D>transform(AffineTransform2D trans)Transforms each curve, and build a new CurveArray2D with the set of transformed curves.java.util.Collection<Point2D>vertices()Implementation of getVertices() for curve returns the same result as the method getSingularPoints().
-
-
-
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(CurveSet2D<? extends T> set)
-
CurveArray2D
public CurveArray2D(java.util.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
-
create
public static <T extends Curve2D> CurveArray2D<T> create(java.util.Collection<T> curves)
Static factory for creating a new CurveArray2D from a collection of curves.- Since:
- 0.8.1
-
create
public static <T extends Curve2D> CurveArray2D<T> create(T... curves)
Static factory for creating a new CurveArray2D from an array of curves.- Since:
- 0.8.1
-
localPosition
public double localPosition(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.- Specified by:
localPositionin interfaceCurveSet2D<T extends Curve2D>- Parameters:
t- the position on the curve set- Returns:
- the position on the subcurve
- See Also:
globalPosition(int, double),curveIndex(double)
-
globalPosition
public double globalPosition(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).- Specified by:
globalPositionin interfaceCurveSet2D<T extends Curve2D>- Parameters:
i- the index of the curve to considert- the position on the curve- Returns:
- the position on the curve set, between 0 and 2*Nc-1
- See Also:
localPosition(double),curveIndex(double)
-
curveIndex
public int curveIndex(double t)
Returns the index of the curve corresponding to a given position.- Specified by:
curveIndexin interfaceCurveSet2D<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
-
add
public boolean add(T curve)
Adds the curve to the curve set, if it does not already belongs to the set.- Specified by:
addin interfaceShapeSet2D<T extends Curve2D>- Parameters:
curve- the curve to add
-
add
public void add(int index, T curve)Description copied from interface:ShapeSet2DInserts the specified shape at the specified position in this set (optional operation).- Specified by:
addin interfaceShapeSet2D<T extends Curve2D>
-
remove
public boolean remove(T curve)
Removes the specified curve from the curve set.- Specified by:
removein interfaceShapeSet2D<T extends Curve2D>- Parameters:
curve- the curve to remove
-
remove
public T remove(int index)
Description copied from interface:ShapeSet2DRemoves the shape at the specified position in this set (optional operation).- Specified by:
removein interfaceShapeSet2D<T extends Curve2D>
-
contains
public boolean contains(T curve)
Checks if the curve set contains the given curve.- Specified by:
containsin interfaceCurveSet2D<T extends Curve2D>- Specified by:
containsin interfaceShapeSet2D<T extends Curve2D>
-
indexOf
public int indexOf(T curve)
Returns index of the given curve within the inner array.- Specified by:
indexOfin interfaceShapeSet2D<T extends Curve2D>
-
clear
public void clear()
Clears the inner curve collection.- Specified by:
clearin interfaceShapeSet2D<T extends Curve2D>
-
curves
public java.util.Collection<T> curves()
Returns the collection of curves- Specified by:
curvesin interfaceCurveSet2D<T extends Curve2D>- Returns:
- the inner collection of curves
-
get
public T get(int index)
Returns the inner curve corresponding to the given index.- Specified by:
getin interfaceCurveSet2D<T extends Curve2D>- Specified by:
getin interfaceShapeSet2D<T extends Curve2D>- Parameters:
index- index of the curve- Returns:
- the i-th inner curve
- Since:
- 0.6.3
-
childCurve
public T childCurve(double t)
Returns the child curve corresponding to a given position.- Specified by:
childCurvein interfaceCurveSet2D<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
-
firstCurve
public T firstCurve()
Returns the first curve of the collection if it exists, null otherwise.- Specified by:
firstCurvein interfaceCurveSet2D<T extends Curve2D>- Returns:
- the first curve of the collection
-
lastCurve
public T lastCurve()
Returns the last curve of the collection if it exists, null otherwise.- Specified by:
lastCurvein interfaceCurveSet2D<T extends Curve2D>- Returns:
- the last curve of the collection
-
size
public int size()
Returns the number of curves in the collection- Specified by:
sizein interfaceShapeSet2D<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.
-
intersections
public java.util.Collection<Point2D> intersections(LinearShape2D line)
Description copied from interface:Curve2DReturns the intersection points of the curve with the specified line. The length of the result array is the number of intersection points.- Specified by:
intersectionsin interfaceCurve2D
-
getT0
@Deprecated public double getT0()
Deprecated. replaced by t0() (since 0.11.1).
-
t1
public double t1()
Description copied from interface:Curve2DGet 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.
-
getT1
@Deprecated public double getT1()
Deprecated. replaced by t1() (since 0.11.1).
-
point
public Point2D point(double t)
Description copied from interface:Curve2DReturns the point located at the given position on 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.
-
firstPoint
public Point2D firstPoint()
Returns the first point of the curve.- Specified by:
firstPointin interfaceCurve2D- Returns:
- the first point of the curve
- See Also:
Curve2D.t0(),Curve2D.point(double)
-
lastPoint
public Point2D lastPoint()
Returns the last point of the curve.- Specified by:
lastPointin interfaceCurve2D- Returns:
- the last point of the curve.
- See Also:
Curve2D.t1(),Curve2D.point(double)
-
singularPoints
public java.util.Collection<Point2D> singularPoints()
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:
singularPointsin interfaceCurve2D- Returns:
- a collection of Point2D.
- See Also:
vertices()
-
vertices
public java.util.Collection<Point2D> vertices()
Implementation of getVertices() for curve returns the same result as the method getSingularPoints().- Specified by:
verticesin interfaceCurve2D- Returns:
- a collection of Point2D.
- See Also:
singularPoints()
-
isSingular
public boolean isSingular(double pos)
Description copied from interface:Curve2DChecks if a point is singular.- Specified by:
isSingularin interfaceCurve2D- Parameters:
pos- the position of the point on the curve- Returns:
- true if the point at this location is singular
-
position
public double position(Point2D point)
Description copied from interface:Curve2DComputes the position of the point on the curve. If the point does not belong to the curve, return Double.NaN. It is complementary to thepoint(double)method.- Specified by:
positionin interfaceCurve2D- Parameters:
point- a point belonging to the curve- Returns:
- the position of the point on the curve
- See Also:
Curve2D.point(double)
-
project
public double project(Point2D point)
Description copied from interface:Curve2DReturns 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.
-
reverse
public Curve2D reverse()
Description copied from interface:Curve2DReturns the curve with same trace on the plane with parameterization in reverse order.
-
subCurve
public CurveSet2D<? extends Curve2D> subCurve(double t0, double t1)
Return an instance of CurveArray2D.
-
distance
public double distance(Point2D p)
Description copied from interface:Shape2DReturns 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.
-
distance
public double distance(double x, double y)Description copied from interface:Shape2DReturns 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.
-
isBounded
public boolean isBounded()
return true, if all curve pieces are bounded
-
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.
-
boundingBox
public Box2D boundingBox()
Returns bounding box for the CurveArray2D.- Specified by:
boundingBoxin interfaceShape2D- 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.
-
continuousCurves
public java.util.Collection<? extends ContinuousCurve2D> continuousCurves()
Description copied from interface:Curve2DReturns the collection of continuous curves which constitute this curve.- Specified by:
continuousCurvesin interfaceCurve2D- Returns:
- a collection of continuous curves.
-
contains
public boolean contains(Point2D p)
Returns true if one of the curves contains the point
-
contains
public boolean contains(double x, double y)Returns true if one of the curves contains the point
-
getGeneralPath
public java.awt.geom.GeneralPath getGeneralPath()
-
asAwtShape
public java.awt.Shape asAwtShape()
- Specified by:
asAwtShapein interfaceCurve2D- Returns:
- the shape corresponding to this curve
-
draw
public void draw(java.awt.Graphics2D g2)
Description copied from interface:Curve2DDraws the curve on the given Graphics2D object.
-
almostEquals
public boolean almostEquals(GeometricObject2D obj, double eps)
Description copied from interface:GeometricObject2DChecks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.- Specified by:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- a threshold value, for example the minimal coordinate difference- Returns:
- true if both object have the same value up to the threshold
-
equals
public 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.- Overrides:
equalsin classjava.lang.Object
-
clone
@Deprecated public CurveArray2D<? extends Curve2D> clone()
Deprecated. use copy constructor instead (0.11.2)
-
-
DMelt 3.0 © DataMelt by jWork.ORG