- Direct Known Subclasses:
QuadCurve2D.Double,QuadCurve2D.Float
public abstract class QuadCurve2D extends Object implements Shape, Cloneable
QuadCurve2D class defines a quadratic parametric curve
segment in (x,y) coordinate space.
This class is only the abstract superclass for all objects that store a 2D quadratic curve segment. The actual storage representation of the coordinates is left to the subclass.
- Since:
- 1.2
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuadCurve2D.DoubleA quadratic parametric curve segment specified withdoublecoordinates.static classQuadCurve2D.FloatA quadratic parametric curve segment specified withfloatcoordinates. -
Constructor Summary
Constructors Modifier Constructor Description protectedQuadCurve2D()This is an abstract class that cannot be instantiated directly. -
Method Summary
Modifier and Type Method Description Objectclone()Creates a new object of the same class and with the same contents 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.booleancontains(Point2D p)Tests if a specifiedPoint2Dis inside the boundary of theShape, as described by the definition of insideness.booleancontains(Rectangle2D r)Tests if the interior of theShapeentirely contains the specifiedRectangle2D.RectanglegetBounds()Returns an integerRectanglethat completely encloses theShape.abstract Point2DgetCtrlPt()Returns the control point.abstract doublegetCtrlX()Returns the X coordinate of the control point indoubleprecision.abstract doublegetCtrlY()Returns the Y coordinate of the control point indoubleprecision.doublegetFlatness()Returns the flatness, or maximum distance of a control point from the line connecting the end points, of thisQuadCurve2D.static doublegetFlatness(double[] coords, int offset)Returns the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the control points stored in the indicated array at the indicated index.static doublegetFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Returns the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the indicated control points.doublegetFlatnessSq()Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of thisQuadCurve2D.static doublegetFlatnessSq(double[] coords, int offset)Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the control points stored in the indicated array at the indicated index.static doublegetFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the indicated control points.abstract Point2DgetP1()Returns the start point.abstract Point2DgetP2()Returns the end point.PathIteratorgetPathIterator(AffineTransform at)Returns an iteration object that defines the boundary of the shape of thisQuadCurve2D.PathIteratorgetPathIterator(AffineTransform at, double flatness)Returns an iteration object that defines the boundary of the flattened shape of thisQuadCurve2D.abstract doublegetX1()Returns the X coordinate of the start point indoublein precision.abstract doublegetX2()Returns the X coordinate of the end point indoubleprecision.abstract doublegetY1()Returns the Y coordinate of the start point indoubleprecision.abstract doublegetY2()Returns the Y coordinate of the end point indoubleprecision.booleanintersects(double x, double y, double w, double h)Tests if the interior of theShapeintersects the interior of a specified rectangular area.booleanintersects(Rectangle2D r)Tests 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 thisQuadCurve2Dto thedoublecoordinates at the specified offset in the specified array.abstract voidsetCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Sets the location of the end points and control point of this curve to the specifieddoublecoordinates.voidsetCurve(Point2D[] pts, int offset)Sets the location of the end points and control points of thisQuadCurve2Dto the coordinates of thePoint2Dobjects at the specified offset in the specified array.voidsetCurve(Point2D p1, Point2D cp, Point2D p2)Sets the location of the end points and control point of thisQuadCurve2Dto the specifiedPoint2Dcoordinates.voidsetCurve(QuadCurve2D c)Sets the location of the end points and control point of thisQuadCurve2Dto the same as those in the specifiedQuadCurve2D.static intsolveQuadratic(double[] eqn)Solves the quadratic whose coefficients are in theeqnarray and places the non-complex roots back into the same array, returning the number of roots.static intsolveQuadratic(double[] eqn, double[] res)Solves the quadratic whose coefficients are in theeqnarray and places 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 quadratic curve specified by the coordinates stored in thesrcarray at indicessrcoffthroughsrcoff+ 5 and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.voidsubdivide(QuadCurve2D left, QuadCurve2D right)Subdivides thisQuadCurve2Dand stores the resulting two subdivided curves into theleftandrightcurve parameters.static voidsubdivide(QuadCurve2D src, QuadCurve2D left, QuadCurve2D right)Subdivides the quadratic curve specified by thesrcparameter and stores the resulting two subdivided curves into theleftandrightcurve parameters.
-
Constructor Details
-
QuadCurve2D
protected QuadCurve2D()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:
QuadCurve2D.Float,QuadCurve2D.Double
-
-
Method Details
-
getX1
public abstract double getX1()Returns the X coordinate of the start point indoublein precision.- Returns:
- the X coordinate of the start point.
- Since:
- 1.2
-
getY1
public abstract double getY1()Returns the Y coordinate of the start point indoubleprecision.- Returns:
- the Y coordinate of the start point.
- Since:
- 1.2
-
getP1
Returns the start point.- Returns:
- a
Point2Dthat is the start point of thisQuadCurve2D. - Since:
- 1.2
-
getCtrlX
public abstract double getCtrlX()Returns the X coordinate of the control point indoubleprecision.- Returns:
- X coordinate the control point
- Since:
- 1.2
-
getCtrlY
public abstract double getCtrlY()Returns the Y coordinate of the control point indoubleprecision.- Returns:
- the Y coordinate of the control point.
- Since:
- 1.2
-
getCtrlPt
Returns the control point.- Returns:
- a
Point2Dthat is the control point of thisPoint2D. - Since:
- 1.2
-
getX2
public abstract double getX2()Returns the X coordinate of the end point indoubleprecision.- Returns:
- the x coordinate of the end point.
- Since:
- 1.2
-
getY2
public abstract double getY2()Returns the Y coordinate of the end point indoubleprecision.- Returns:
- the Y coordinate of the end point.
- Since:
- 1.2
-
getP2
Returns the end point.- Returns:
- a
Pointobject that is the end point of thisPoint2D. - Since:
- 1.2
-
setCurve
public abstract void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Sets the location of the end points and control point of this curve to the specifieddoublecoordinates.- Parameters:
x1- the X coordinate of the start pointy1- the Y coordinate of the start pointctrlx- the X coordinate of the control pointctrly- the Y coordinate of the control pointx2- the X coordinate of the end pointy2- the Y coordinate of the end point- Since:
- 1.2
-
setCurve
public void setCurve(double[] coords, int offset)Sets the location of the end points and control points of thisQuadCurve2Dto thedoublecoordinates at the specified offset in the specified array.- Parameters:
coords- the array containing coordinate valuesoffset- the index into the array from which to start getting the coordinate values and assigning them to thisQuadCurve2D- Since:
- 1.2
-
setCurve
Sets the location of the end points and control point of thisQuadCurve2Dto the specifiedPoint2Dcoordinates.- Parameters:
p1- the start pointcp- the control pointp2- the end point- Since:
- 1.2
-
setCurve
Sets the location of the end points and control points of thisQuadCurve2Dto the coordinates of thePoint2Dobjects at the specified offset in the specified array.- Parameters:
pts- an array containingPoint2Dthat define coordinate valuesoffset- the index intoptsfrom which to start getting the coordinate values and assigning them to thisQuadCurve2D- Since:
- 1.2
-
setCurve
Sets the location of the end points and control point of thisQuadCurve2Dto the same as those in the specifiedQuadCurve2D.- Parameters:
c- the specifiedQuadCurve2D- Since:
- 1.2
-
getFlatnessSq
public static double getFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the indicated control points.- Parameters:
x1- the X coordinate of the start pointy1- the Y coordinate of the start pointctrlx- the X coordinate of the control pointctrly- the Y coordinate of the control pointx2- the X coordinate of the end pointy2- the Y coordinate of the end point- Returns:
- the square of the flatness of the quadratic curve defined by the specified coordinates.
- Since:
- 1.2
-
getFlatness
public static double getFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)Returns the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the indicated control points.- Parameters:
x1- the X coordinate of the start pointy1- the Y coordinate of the start pointctrlx- the X coordinate of the control pointctrly- the Y coordinate of the control pointx2- the X coordinate of the end pointy2- the Y coordinate of the end point- Returns:
- the flatness of the quadratic curve defined by the specified coordinates.
- Since:
- 1.2
-
getFlatnessSq
public static double getFlatnessSq(double[] coords, int offset)Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the control points stored in the indicated array at the indicated index.- Parameters:
coords- an array containing coordinate valuesoffset- the index intocoordsfrom which to to start getting the values from the array- Returns:
- the flatness of the quadratic curve that is defined by the values in the specified array at the specified index.
- Since:
- 1.2
-
getFlatness
public static double getFlatness(double[] coords, int offset)Returns the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the control points stored in the indicated array at the indicated index.- Parameters:
coords- an array containing coordinate valuesoffset- the index intocoordsfrom which to start getting the coordinate values- Returns:
- the flatness of a quadratic curve defined by the specified array at the specified offset.
- Since:
- 1.2
-
getFlatnessSq
public double getFlatnessSq()Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of thisQuadCurve2D.- Returns:
- the square of the flatness of this
QuadCurve2D. - Since:
- 1.2
-
getFlatness
public double getFlatness()Returns the flatness, or maximum distance of a control point from the line connecting the end points, of thisQuadCurve2D.- Returns:
- the flatness of this
QuadCurve2D. - Since:
- 1.2
-
subdivide
Subdivides thisQuadCurve2Dand stores the resulting two subdivided curves into theleftandrightcurve parameters. Either or both of theleftandrightobjects can be the same as thisQuadCurve2Dornull.- Parameters:
left- theQuadCurve2Dobject for storing the left or first half of the subdivided curveright- theQuadCurve2Dobject for storing the right or second half of the subdivided curve- Since:
- 1.2
-
subdivide
Subdivides the quadratic curve specified by thesrcparameter and stores the resulting two subdivided curves into theleftandrightcurve parameters. Either or both of theleftandrightobjects can be the same as thesrcobject ornull.- Parameters:
src- the quadratic curve to be subdividedleft- theQuadCurve2Dobject for storing the left or first half of the subdivided curveright- theQuadCurve2Dobject for storing the right or second half of the subdivided curve- Since:
- 1.2
-
subdivide
public static void subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff)Subdivides the quadratic curve specified by the coordinates stored in thesrcarray at indicessrcoffthroughsrcoff+ 5 and stores the resulting two subdivided curves into the two result arrays at the corresponding indices. Either or both of theleftandrightarrays can benullor a reference to the same array and offset 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 thatrightoffequalsleftoff+ 4 in order to avoid allocating extra storage for this common point.- Parameters:
src- the array holding the coordinates for the source curvesrcoff- the offset into the array of the beginning of the the 6 source coordinatesleft- the array for storing the coordinates for the first half of the subdivided curveleftoff- the offset into the array of the beginning of the the 6 left coordinatesright- the array for storing the coordinates for the second half of the subdivided curverightoff- the offset into the array of the beginning of the the 6 right coordinates- Since:
- 1.2
-
solveQuadratic
public static int solveQuadratic(double[] eqn)Solves the quadratic whose coefficients are in theeqnarray and places the non-complex roots back into the same array, returning the number of roots. The quadratic solved is represented by the equation:eqn = {C, B, A}; ax^2 + bx + c = 0A return value of-1is used to distinguish a constant equation, which might be always 0 or never 0, from an equation that has no zeroes.- Parameters:
eqn- the array that contains the quadratic coefficients- Returns:
- the number of roots, or
-1if the equation is a constant - Since:
- 1.2
-
solveQuadratic
public static int solveQuadratic(double[] eqn, double[] res)Solves the quadratic whose coefficients are in theeqnarray and places the non-complex roots into theresarray, returning the number of roots. The quadratic solved is represented by the equation:eqn = {C, B, A}; ax^2 + bx + c = 0A return value of-1is used to distinguish a constant equation, which might be always 0 or never 0, from an equation that has no zeroes.- Parameters:
eqn- the specified array of coefficients to use to solve the quadratic equationres- the array that contains the non-complex roots resulting from the solution of the quadratic equation- Returns:
- the number of roots, or
-1if the equation is a constant. - Since:
- 1.3
-
contains
public boolean contains(double x, double y)Tests if the specified coordinates are inside the boundary of theShape, as described by the definition of insideness. -
contains
Tests if a specifiedPoint2Dis inside the boundary of theShape, as described by the definition of insideness. -
intersects
public 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 interfaceShape- Parameters:
x- the X coordinate of the upper-left corner of the specified rectangular areay- the Y coordinate of the upper-left corner of the specified rectangular areaw- the width of the specified rectangular areah- the height of the specified rectangular area- Returns:
trueif the interior of theShapeand 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:
Area
-
there is a high probability that the rectangular area and the
-
intersects
Tests 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 interfaceShape- Parameters:
r- the specifiedRectangle2D- Returns:
trueif the interior of theShapeand the interior of the specifiedRectangle2Dintersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;falseotherwise.- Since:
- 1.2
- See Also:
Shape.intersects(double, double, double, double)
-
there is a high probability that the
-
contains
public 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 interfaceShape- Parameters:
x- the X coordinate of the upper-left corner of the specified rectangular areay- the Y coordinate of the upper-left corner of the specified rectangular areaw- the width of the specified rectangular areah- the height of the specified rectangular area- Returns:
trueif the interior of theShapeentirely contains the specified rectangular area;falseotherwise or, if theShapecontains the rectangular area and theintersectsmethod returnstrueand the containment calculations would be too expensive to perform.- Since:
- 1.2
- See Also:
Area,Shape.intersects(double, double, double, double)
-
the
-
contains
Tests 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 interfaceShape- Parameters:
r- The specifiedRectangle2D- Returns:
trueif the interior of theShapeentirely contains theRectangle2D;falseotherwise or, if theShapecontains theRectangle2Dand theintersectsmethod returnstrueand the containment calculations would be too expensive to perform.- Since:
- 1.2
- See Also:
Shape.contains(double, double, double, double)
-
the
-
getBounds
Returns 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)- Specified by:
getBoundsin interfaceShape- Returns:
- an integer
Rectanglethat completely encloses theShape. - Since:
- 1.2
- See Also:
Shape.getBounds2D()
-
getPathIterator
Returns an iteration object that defines the boundary of the shape of thisQuadCurve2D. The iterator for this class is not multi-threaded safe, which means that thisQuadCurve2Dclass does not guarantee that modifications to the geometry of thisQuadCurve2Dobject do not affect any iterations of that geometry that are already in process.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- an optionalAffineTransformto apply to the shape boundary- Returns:
- a
PathIteratorobject that defines the boundary of the shape. - Since:
- 1.2
-
getPathIterator
Returns an iteration object that defines the boundary of the flattened shape of thisQuadCurve2D. The iterator for this class is not multi-threaded safe, which means that thisQuadCurve2Dclass does not guarantee that modifications to the geometry of thisQuadCurve2Dobject do not affect any iterations of that geometry that are already in process.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- an optionalAffineTransformto apply to the boundary of the shapeflatness- the maximum distance that the control points for a subdivided curve can be with respect to a line connecting the end points of this curve before this curve is replaced by a straight line connecting the end points.- Returns:
- a
PathIteratorobject that defines the flattened boundary of the shape. - Since:
- 1.2
-
clone
Creates a new object of the same class and with the same contents as this object.- Overrides:
clonein classObject- Returns:
- a clone of this instance.
- Throws:
OutOfMemoryError- if there is not enough memory.- Since:
- 1.2
- See Also:
Cloneable
-