Class CubicCurve2D
- Direct Known Subclasses:
- CubicCurve2D.Double,- CubicCurve2D.Float
CubicCurve2D class defines a cubic parametric curve
 segment in (x,y) coordinate space.
 This class is only the abstract superclass for all objects which store a 2D cubic curve segment. The actual storage representation of the coordinates is left to the subclass.
- Since:
- 1.2
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA cubic parametric curve segment specified withdoublecoordinates.static classA cubic parametric curve segment specified withfloatcoordinates.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedThis is an abstract class that cannot be instantiated directly.
- 
Method SummaryModifier and TypeMethodDescriptionclone()Creates a new object of the same class as this object.booleancontains(double x, double y) Tests if the specified coordinates are inside the boundary of theShape, as described by the definition of insideness.booleancontains(double x, double y, double w, double h) Tests if the interior of theShapeentirely contains the specified rectangular area.booleanTests if a specifiedPoint2Dis inside the boundary of theShape, as described by the definition of insideness.booleanTests if the interior of theShapeentirely contains the specifiedRectangle2D.Returns an integerRectanglethat completely encloses theShape.Returns a high precision and more accurate bounding box of theShapethan thegetBoundsmethod.abstract Point2DReturns the first control point.abstract Point2DReturns the second control point.abstract doubleReturns the X coordinate of the first control point in double precision.abstract doubleReturns the X coordinate of the second control point in double precision.abstract doubleReturns the Y coordinate of the first control point in double precision.abstract doubleReturns the Y coordinate of the second control point in double precision.doubleReturns the flatness of this curve.static doublegetFlatness(double[] coords, int offset) Returns the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index.static doublegetFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Returns the flatness of the cubic curve specified by the indicated control points.doubleReturns the square of the flatness of this curve.static doublegetFlatnessSq(double[] coords, int offset) Returns the square of the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index.static doublegetFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Returns the square of the flatness of the cubic curve specified by the indicated control points.abstract Point2DgetP1()Returns the start point.abstract Point2DgetP2()Returns the end point.Returns an iteration object that defines the boundary of the shape.getPathIterator(AffineTransform at, double flatness) Return an iteration object that defines the boundary of the flattened shape.abstract doublegetX1()Returns the X coordinate of the start point in double precision.abstract doublegetX2()Returns the X coordinate of the end point in double precision.abstract doublegetY1()Returns the Y coordinate of the start point in double precision.abstract doublegetY2()Returns the Y coordinate of the end point in double precision.booleanintersects(double x, double y, double w, double h) Tests if the interior of theShapeintersects the interior of a specified rectangular area.booleanTests if the interior of theShapeintersects the interior of a specifiedRectangle2D.voidsetCurve(double[] coords, int offset) Sets the location of the end points and control points of this curve to the double coordinates at the specified offset in the specified array.abstract voidsetCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Sets the location of the end points and control points of this curve to the specified double coordinates.voidSets the location of the end points and control points of this curve to the same as those in the specifiedCubicCurve2D.voidSets the location of the end points and control points of this curve to the coordinates of thePoint2Dobjects at the specified offset in the specified array.voidSets the location of the end points and control points of this curve to the specifiedPoint2Dcoordinates.static intsolveCubic(double[] eqn) Solves the cubic whose coefficients are in theeqnarray and places the non-complex roots back into the same array, returning the number of roots.static intsolveCubic(double[] eqn, double[] res) Solve the cubic whose coefficients are in theeqnarray and place the non-complex roots into theresarray, returning the number of roots.static voidsubdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff) Subdivides the cubic curve specified by the coordinates stored in thesrcarray at indicessrcoffthrough (srcoff+ 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.voidsubdivide(CubicCurve2D left, CubicCurve2D right) Subdivides this cubic curve and stores the resulting two subdivided curves into the left and right curve parameters.static voidsubdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right) Subdivides the cubic curve specified by thesrcparameter and stores the resulting two subdivided curves into theleftandrightcurve parameters.
- 
Constructor Details- 
CubicCurve2Dprotected CubicCurve2D()This is an abstract class that cannot be instantiated directly. Type-specific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessor methods below.- Since:
- 1.2
- See Also:
 
 
- 
- 
Method Details- 
getX1public abstract double getX1()Returns the X coordinate of the start point in double precision.- Returns:
- the X coordinate of the start point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getY1public abstract double getY1()Returns the Y coordinate of the start point in double precision.- Returns:
- the Y coordinate of the start point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getP1Returns the start point.- Returns:
- a Point2Dthat is the start point of theCubicCurve2D.
- Since:
- 1.2
 
- 
getCtrlX1public abstract double getCtrlX1()Returns the X coordinate of the first control point in double precision.- Returns:
- the X coordinate of the first control point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getCtrlY1public abstract double getCtrlY1()Returns the Y coordinate of the first control point in double precision.- Returns:
- the Y coordinate of the first control point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getCtrlP1Returns the first control point.- Returns:
- a Point2Dthat is the first control point of theCubicCurve2D.
- Since:
- 1.2
 
- 
getCtrlX2public abstract double getCtrlX2()Returns the X coordinate of the second control point in double precision.- Returns:
- the X coordinate of the second control point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getCtrlY2public abstract double getCtrlY2()Returns the Y coordinate of the second control point in double precision.- Returns:
- the Y coordinate of the second control point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getCtrlP2Returns the second control point.- Returns:
- a Point2Dthat is the second control point of theCubicCurve2D.
- Since:
- 1.2
 
- 
getX2public abstract double getX2()Returns the X coordinate of the end point in double precision.- Returns:
- the X coordinate of the end point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getY2public abstract double getY2()Returns the Y coordinate of the end point in double precision.- Returns:
- the Y coordinate of the end point of the
         CubicCurve2D.
- Since:
- 1.2
 
- 
getP2Returns the end point.- Returns:
- a Point2Dthat is the end point of theCubicCurve2D.
- Since:
- 1.2
 
- 
setCurvepublic abstract void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Sets the location of the end points and control points of this curve to the specified double coordinates.- Parameters:
- x1- the X coordinate used to set the start point of this- CubicCurve2D
- y1- the Y coordinate used to set the start point of this- CubicCurve2D
- ctrlx1- the X coordinate used to set the first control point of this- CubicCurve2D
- ctrly1- the Y coordinate used to set the first control point of this- CubicCurve2D
- ctrlx2- the X coordinate used to set the second control point of this- CubicCurve2D
- ctrly2- the Y coordinate used to set the second control point of this- CubicCurve2D
- x2- the X coordinate used to set the end point of this- CubicCurve2D
- y2- the Y coordinate used to set the end point of this- CubicCurve2D
- Since:
- 1.2
 
- 
setCurvepublic void setCurve(double[] coords, int offset) Sets the location of the end points and control points of this curve to the double coordinates at the specified offset in the specified array.- Parameters:
- coords- a double array containing coordinates
- offset- the index of- coordsfrom which to begin setting the end points and control points of this curve to the coordinates contained in- coords
- Since:
- 1.2
 
- 
setCurveSets the location of the end points and control points of this curve to the specifiedPoint2Dcoordinates.- Parameters:
- p1- the first specified- Point2Dused to set the start point of this curve
- cp1- the second specified- Point2Dused to set the first control point of this curve
- cp2- the third specified- Point2Dused to set the second control point of this curve
- p2- the fourth specified- Point2Dused to set the end point of this curve
- Since:
- 1.2
 
- 
setCurveSets the location of the end points and control points of this curve to the coordinates of thePoint2Dobjects at the specified offset in the specified array.- Parameters:
- pts- an array of- Point2Dobjects
- offset- the index of- ptsfrom which to begin setting the end points and control points of this curve to the points contained in- pts
- Since:
- 1.2
 
- 
setCurveSets the location of the end points and control points of this curve to the same as those in the specifiedCubicCurve2D.- Parameters:
- c- the specified- CubicCurve2D
- Since:
- 1.2
 
- 
getFlatnessSqpublic static double getFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Returns the square of the flatness of the cubic curve specified by the indicated control points. The flatness is the maximum distance of a control point from the line connecting the end points.- Parameters:
- x1- the X coordinate that specifies the start point of a- CubicCurve2D
- y1- the Y coordinate that specifies the start point of a- CubicCurve2D
- ctrlx1- the X coordinate that specifies the first control point of a- CubicCurve2D
- ctrly1- the Y coordinate that specifies the first control point of a- CubicCurve2D
- ctrlx2- the X coordinate that specifies the second control point of a- CubicCurve2D
- ctrly2- the Y coordinate that specifies the second control point of a- CubicCurve2D
- x2- the X coordinate that specifies the end point of a- CubicCurve2D
- y2- the Y coordinate that specifies the end point of a- CubicCurve2D
- Returns:
- the square of the flatness of the CubicCurve2Drepresented by the specified coordinates.
- Since:
- 1.2
 
- 
getFlatnesspublic static double getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Returns the flatness of the cubic curve specified by the indicated control points. The flatness is the maximum distance of a control point from the line connecting the end points.- Parameters:
- x1- the X coordinate that specifies the start point of a- CubicCurve2D
- y1- the Y coordinate that specifies the start point of a- CubicCurve2D
- ctrlx1- the X coordinate that specifies the first control point of a- CubicCurve2D
- ctrly1- the Y coordinate that specifies the first control point of a- CubicCurve2D
- ctrlx2- the X coordinate that specifies the second control point of a- CubicCurve2D
- ctrly2- the Y coordinate that specifies the second control point of a- CubicCurve2D
- x2- the X coordinate that specifies the end point of a- CubicCurve2D
- y2- the Y coordinate that specifies the end point of a- CubicCurve2D
- Returns:
- the flatness of the CubicCurve2Drepresented by the specified coordinates.
- Since:
- 1.2
 
- 
getFlatnessSqpublic static double getFlatnessSq(double[] coords, int offset) Returns the square of the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index. The flatness is the maximum distance of a control point from the line connecting the end points.- Parameters:
- coords- an array containing coordinates
- offset- the index of- coordsfrom which to begin getting the end points and control points of the curve
- Returns:
- the square of the flatness of the CubicCurve2Dspecified by the coordinates incoordsat the specified offset.
- Since:
- 1.2
 
- 
getFlatnesspublic static double getFlatness(double[] coords, int offset) Returns the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index. The flatness is the maximum distance of a control point from the line connecting the end points.- Parameters:
- coords- an array containing coordinates
- offset- the index of- coordsfrom which to begin getting the end points and control points of the curve
- Returns:
- the flatness of the CubicCurve2Dspecified by the coordinates incoordsat the specified offset.
- Since:
- 1.2
 
- 
getFlatnessSqpublic double getFlatnessSq()Returns the square of the flatness of this curve. The flatness is the maximum distance of a control point from the line connecting the end points.- Returns:
- the square of the flatness of this curve.
- Since:
- 1.2
 
- 
getFlatnesspublic double getFlatness()Returns the flatness of this curve. The flatness is the maximum distance of a control point from the line connecting the end points.- Returns:
- the flatness of this curve.
- Since:
- 1.2
 
- 
subdivideSubdivides this cubic curve and stores the resulting two subdivided curves into the left and right curve parameters. Either or both of the left and right objects may be the same as this object or null.- Parameters:
- left- the cubic curve object for storing for the left or first half of the subdivided curve
- right- the cubic curve object for storing for the right or second half of the subdivided curve
- Since:
- 1.2
 
- 
subdivideSubdivides the cubic curve specified by thesrcparameter and stores the resulting two subdivided curves into theleftandrightcurve parameters. Either or both of theleftandrightobjects may be the same as thesrcobject ornull.- Parameters:
- src- the cubic curve to be subdivided
- left- the cubic curve object for storing the left or first half of the subdivided curve
- right- the cubic curve object for storing the right or second half of the subdivided curve
- Since:
- 1.2
 
- 
subdividepublic static void subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff) Subdivides the cubic curve specified by the coordinates stored in thesrcarray at indicessrcoffthrough (srcoff+ 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices. Either or both of theleftandrightarrays may benullor a reference to the same array as thesrcarray. Note that the last point in the first subdivided curve is the same as the first point in the second subdivided curve. Thus, it is possible to pass the same array forleftandrightand to use offsets, such asrightoffequals (leftoff+ 6), in order to avoid allocating extra storage for this common point.- Parameters:
- src- the array holding the coordinates for the source curve
- srcoff- the offset into the array of the beginning of the the 6 source coordinates
- left- the array for storing the coordinates for the first half of the subdivided curve
- leftoff- the offset into the array of the beginning of the the 6 left coordinates
- right- the array for storing the coordinates for the second half of the subdivided curve
- rightoff- the offset into the array of the beginning of the the 6 right coordinates
- Since:
- 1.2
 
- 
solveCubicpublic static int solveCubic(double[] eqn) Solves the cubic whose coefficients are in theeqnarray and places the non-complex roots back into the same array, returning the number of roots. The solved cubic is represented by the equation:eqn = {c, b, a, d} dx^3 + ax^2 + bx + c = 0A return value of -1 is used to distinguish a constant equation that might be always 0 or never 0 from an equation that has no zeroes.- Parameters:
- eqn- an array containing coefficients for a cubic
- Returns:
- the number of roots, or -1 if the equation is a constant.
- Since:
- 1.2
 
- 
solveCubicpublic static int solveCubic(double[] eqn, double[] res) Solve the cubic whose coefficients are in theeqnarray and place the non-complex roots into theresarray, returning the number of roots. The cubic solved is represented by the equation: eqn = {c, b, a, d} dx^3 + ax^2 + bx + c = 0 A return value of -1 is used to distinguish a constant equation, which may be always 0 or never 0, from an equation which has no zeroes.- Parameters:
- eqn- the specified array of coefficients to use to solve the cubic equation
- res- the array that contains the non-complex roots resulting from the solution of the cubic equation
- Returns:
- the number of roots, or -1 if the equation is a constant
- Since:
- 1.3
 
- 
containspublic boolean contains(double x, double y) Tests if the specified coordinates are inside the boundary of theShape, as described by the definition of insideness.
- 
containsTests if a specifiedPoint2Dis inside the boundary of theShape, as described by the definition of insideness.
- 
intersectspublic boolean intersects(double x, double y, double w, double h) Tests if the interior of theShapeintersects the interior of a specified rectangular area. The rectangular area is considered to intersect theShapeif any point is contained in both the interior of theShapeand the specified rectangular area.The Shape.intersects()method allows aShapeimplementation to conservatively returntruewhen:- 
 there is a high probability that the rectangular area and the
 Shapeintersect, but
- the calculations to accurately determine this intersection are prohibitively expensive.
 Shapesthis method might returntrueeven though the rectangular area does not intersect theShape. TheAreaclass performs more accurate computations of geometric intersection than mostShapeobjects and therefore can be used if a more precise answer is required.- Specified by:
- intersectsin interface- Shape
- Parameters:
- x- the X coordinate of the upper-left corner of the specified rectangular area
- y- the Y coordinate of the upper-left corner of the specified rectangular area
- w- the width of the specified rectangular area
- h- the height of the specified rectangular area
- Returns:
- trueif the interior of the- Shapeand the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;- falseotherwise.
- Since:
- 1.2
- See Also:
 
- 
 there is a high probability that the rectangular area and the
 
- 
intersectsTests if the interior of theShapeintersects the interior of a specifiedRectangle2D. TheShape.intersects()method allows aShapeimplementation to conservatively returntruewhen:- 
 there is a high probability that the Rectangle2Dand theShapeintersect, but
- the calculations to accurately determine this intersection are prohibitively expensive.
 Shapesthis method might returntrueeven though theRectangle2Ddoes not intersect theShape. TheAreaclass performs more accurate computations of geometric intersection than mostShapeobjects and therefore can be used if a more precise answer is required.- Specified by:
- intersectsin interface- Shape
- Parameters:
- r- the specified- Rectangle2D
- Returns:
- trueif the interior of the- Shapeand the interior of the specified- Rectangle2Dintersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;- falseotherwise.
- Since:
- 1.2
- See Also:
 
- 
 there is a high probability that the 
- 
containspublic boolean contains(double x, double y, double w, double h) Tests if the interior of theShapeentirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within theShapefor the entire rectangular area to be considered contained within theShape.The Shape.contains()method allows aShapeimplementation to conservatively returnfalsewhen:- 
 the intersectmethod returnstrueand
- 
 the calculations to determine whether or not the
 Shapeentirely contains the rectangular area are prohibitively expensive.
 Shapesthis method might returnfalseeven though theShapecontains the rectangular area. TheAreaclass performs more accurate geometric computations than mostShapeobjects and therefore can be used if a more precise answer is required.- Specified by:
- containsin interface- Shape
- Parameters:
- x- the X coordinate of the upper-left corner of the specified rectangular area
- y- the Y coordinate of the upper-left corner of the specified rectangular area
- w- the width of the specified rectangular area
- h- the height of the specified rectangular area
- Returns:
- trueif the interior of the- Shapeentirely contains the specified rectangular area;- falseotherwise or, if the- Shapecontains the rectangular area and the- intersectsmethod returns- trueand the containment calculations would be too expensive to perform.
- Since:
- 1.2
- See Also:
 
- 
 the 
- 
containsTests if the interior of theShapeentirely contains the specifiedRectangle2D. TheShape.contains()method allows aShapeimplementation to conservatively returnfalsewhen:- 
 the intersectmethod returnstrueand
- 
 the calculations to determine whether or not the
 Shapeentirely contains theRectangle2Dare prohibitively expensive.
 Shapesthis method might returnfalseeven though theShapecontains theRectangle2D. TheAreaclass performs more accurate geometric computations than mostShapeobjects and therefore can be used if a more precise answer is required.- Specified by:
- containsin interface- Shape
- Parameters:
- r- The specified- Rectangle2D
- Returns:
- trueif the interior of the- Shapeentirely contains the- Rectangle2D;- falseotherwise or, if the- Shapecontains the- Rectangle2Dand the- intersectsmethod returns- trueand the containment calculations would be too expensive to perform.
- Since:
- 1.2
- See Also:
 
- 
 the 
- 
getBounds2DReturns a high precision and more accurate bounding box of theShapethan thegetBoundsmethod. Note that there is no guarantee that the returnedRectangle2Dis the smallest bounding box that encloses theShape, only that theShapelies entirely within the indicatedRectangle2D. The bounding box returned by this method is usually tighter than that returned by thegetBoundsmethod and never fails due to overflow problems since the return value can be an instance of theRectangle2Dthat uses double precision values to store the dimensions.Note that the definition of insideness can lead to situations where points on the defining outline of the shapemay not be considered contained in the returnedboundsobject, but only in cases where those points are also not considered contained in the originalshape.If a pointis inside theshapeaccording to thecontains(point)method, then it must be inside the returnedRectangle2Dbounds object according to thecontains(point)method of thebounds. Specifically:shape.contains(p)requiresbounds.contains(p)If a pointis not inside theshape, then it might still be contained in theboundsobject:bounds.contains(p)does not implyshape.contains(p)- Specified by:
- getBounds2Din interface- Shape
- Returns:
- an instance of Rectangle2Dthat is a high-precision bounding box of theShape.
- Since:
- 1.2
- See Also:
 
- 
getBoundsReturns an integerRectanglethat completely encloses theShape. Note that there is no guarantee that the returnedRectangleis the smallest bounding box that encloses theShape, only that theShapelies entirely within the indicatedRectangle. The returnedRectanglemight also fail to completely enclose theShapeif theShapeoverflows the limited range of the integer data type. ThegetBounds2Dmethod generally returns a tighter bounding box due to its greater flexibility in representation.Note that the definition of insideness can lead to situations where points on the defining outline of the shapemay not be considered contained in the returnedboundsobject, but only in cases where those points are also not considered contained in the originalshape.If a pointis inside theshapeaccording to thecontains(point)method, then it must be inside the returnedRectanglebounds object according to thecontains(point)method of thebounds. Specifically:shape.contains(x,y)requiresbounds.contains(x,y)If a pointis not inside theshape, then it might still be contained in theboundsobject:bounds.contains(x,y)does not implyshape.contains(x,y)
- 
getPathIteratorReturns an iteration object that defines the boundary of the shape. The iterator for this class is not multi-threaded safe, which means that thisCubicCurve2Dclass does not guarantee that modifications to the geometry of thisCubicCurve2Dobject do not affect any iterations of that geometry that are already in process.- Specified by:
- getPathIteratorin interface- Shape
- Parameters:
- at- an optional- AffineTransformto be applied to the coordinates as they are returned in the iteration, or- nullif untransformed coordinates are desired
- Returns:
- the PathIteratorobject that returns the geometry of the outline of thisCubicCurve2D, one segment at a time.
- Since:
- 1.2
 
- 
getPathIteratorReturn an iteration object that defines the boundary of the flattened shape. The iterator for this class is not multi-threaded safe, which means that thisCubicCurve2Dclass does not guarantee that modifications to the geometry of thisCubicCurve2Dobject do not affect any iterations of that geometry that are already in process.- Specified by:
- getPathIteratorin interface- Shape
- Parameters:
- at- an optional- AffineTransformto be applied to the coordinates as they are returned in the iteration, or- nullif untransformed coordinates are desired
- flatness- the maximum amount that the control points for a given curve can vary from colinear before a subdivided curve is replaced by a straight line connecting the end points
- Returns:
- the PathIteratorobject that returns the geometry of the outline of thisCubicCurve2D, one segment at a time.
- Since:
- 1.2
 
- 
cloneCreates a new object of the same class as this object.- Overrides:
- clonein class- Object
- Returns:
- a clone of this instance.
- Throws:
- OutOfMemoryError- if there is not enough memory.
- Since:
- 1.2
- See Also:
 
 
-