Package com.graphbuilder.curve
Class MultiPath
java.lang.Object
com.graphbuilder.curve.MultiPath
- Direct Known Subclasses:
ShapeMultiPath
A multi-path is a series of paths (sequence of connected points) in n-dimensions. The points and
move types (MOVE_TO or LINE_TO) are stored using arrays.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMultiPath(int dimension) Constructs a multi-path specifying the minimum required dimension of each point appended to this multi-path. -
Method Summary
Modifier and TypeMethodDescriptionvoidensureCapacity(int capacity) Checks that the point array has the specified capacity, otherwise the capacity of the point array is increased to be the maximum between twice the current capacity and the specified capacity.double[]get(int index) Returns a reference to the point at the specified index.intReturns the capacity of the internal point array.intReturns the dimension.doublegetDistSq(double[] p) Computes the minimum distance^2 from the specified point to the line segments formed by the points of this multi-path.doubleReturns the flatness.intReturns the size counter.getType(int index) Returns the type of the point at the specified index.voidlineTo(double[] p) Appends a point of type LINE_TO.voidmoveTo(double[] p) Appends a point of type MOVE_TO.voidset(int index, double[] p) Sets the point at the specified index.voidsetFlatness(double f) Sets the flatness.voidsetNumPoints(int n) Sets the size counter.voidSets the type of the point at the specified index.voidCreates a new point array of exact size, copying the points from the old array into the new one.
-
Field Details
-
MOVE_TO
-
LINE_TO
-
-
Constructor Details
-
MultiPath
public MultiPath(int dimension) Constructs a multi-path specifying the minimum required dimension of each point appended to this multi-path.- Throws:
IllegalArgumentException- If dimension <= 0.
-
-
Method Details
-
getDimension
public int getDimension()Returns the dimension. The dimension is used by the BinaryCurveApproximationAlgorithm to know what dimension of points to create. If the dimension of the multi-path is greater than the dimension of the control points for a curve, then an ArrayIndexOutOfBoundsException will occur when the curve is appended to the MultiPath. -
getFlatness
public double getFlatness()Returns the flatness. The flatness is used by the BinaryCurveApproximationAlgorithm to determine how closely the line segements formed by the points of this multi-path should approximate a given curve. The default flatness value is 1.0. When using curves in a graphics environment, the flatness usually inversely proportional to the scale.- See Also:
-
setFlatness
public void setFlatness(double f) Sets the flatness. As the flatness value gets closer to zero, the BinaryCurveApproximationAlgorithm generates more points.- Throws:
IllegalArgumentException- If the flatness is <= 0.- See Also:
-
get
public double[] get(int index) Returns a reference to the point at the specified index.- See Also:
-
set
public void set(int index, double[] p) Sets the point at the specified index.- Throws:
IllegalArgumentException- If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.- See Also:
-
getType
Returns the type of the point at the specified index. The type can other be MultiPath.MOVE_TO or MultiPath.LINE_TO.- See Also:
-
setType
Sets the type of the point at the specified index. The first point must always be MOVE_TO.- Throws:
IllegalArgumentException- If the specified type unknown or the specified index is 0 and type is not MOVE_TO.- See Also:
-
getNumPoints
public int getNumPoints()Returns the size counter.- See Also:
-
setNumPoints
public void setNumPoints(int n) Sets the size counter. The size counter can be changed to any value as long as all points from index location 0 (inclusive) to n (exclusive) are non-null. Thus, the maximum value the size counter can be is the first null index location. Changing the size counter does not remove any of the points.- See Also:
-
getCapacity
public int getCapacity()Returns the capacity of the internal point array. -
ensureCapacity
public void ensureCapacity(int capacity) Checks that the point array has the specified capacity, otherwise the capacity of the point array is increased to be the maximum between twice the current capacity and the specified capacity. -
trimArray
public void trimArray()Creates a new point array of exact size, copying the points from the old array into the new one. -
lineTo
public void lineTo(double[] p) Appends a point of type LINE_TO. If the size counter is 0 then the request is interpretted as a MOVE_TO request.- Throws:
IllegalArgumentException- If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.- See Also:
-
moveTo
public void moveTo(double[] p) Appends a point of type MOVE_TO.- Throws:
IllegalArgumentException- If the point is null or the dimension of the point does not meet the dimension requirement specified in the constructor.- See Also:
-
getDistSq
public double getDistSq(double[] p) Computes the minimum distance^2 from the specified point to the line segments formed by the points of this multi-path. If the size counter is 0 then the value returned is Double.MAX_VALUE.- Throws:
IllegalArgumentException- If the point is null or the length of the point is less than the dimension specified in the constructor.
-