Class QuadCurve2D

java.lang.Object
java.awt.geom.QuadCurve2D
All Implemented Interfaces:
Shape,Cloneable
Direct Known Subclasses:
QuadCurve2D.Double,QuadCurve2D.Float

public abstract classQuadCurve2DextendsObjectimplementsShape,Cloneable
TheQuadCurve2D 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 class 
    A quadratic parametric curve segment specified withdouble coordinates.
    static class 
    A quadratic parametric curve segment specified withfloat coordinates.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    This is an abstract class that cannot be instantiated directly.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new object of the same class and with the same contents as this object.
    boolean
    contains(double x, double y)
    Tests if the specified coordinates are inside the boundary of theShape, as described by thedefinition of insideness.
    boolean
    contains(double x, double y, double w, double h)
    Tests if the interior of theShape entirely contains the specified rectangular area.
    boolean
    Tests if a specifiedPoint2D is inside the boundary of theShape, as described by the definition of insideness.
    boolean
    Tests if the interior of theShape entirely contains the specifiedRectangle2D.
    Returns an integerRectangle that completely encloses theShape.
    Returns a high precision and more accurate bounding box of theShape than thegetBounds method.
    abstractPoint2D
    Returns the control point.
    abstract double
    Returns the X coordinate of the control point indouble precision.
    abstract double
    Returns the Y coordinate of the control point indouble precision.
    double
    Returns the flatness, or maximum distance of a control point from the line connecting the end points, of thisQuadCurve2D.
    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.
    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.
    double
    Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of thisQuadCurve2D.
    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.
    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.
    abstractPoint2D
    Returns the start point.
    abstractPoint2D
    Returns the end point.
    Returns an iteration object that defines the boundary of the shape of thisQuadCurve2D.
    getPathIterator(AffineTransform at, double flatness)
    Returns an iteration object that defines the boundary of the flattened shape of thisQuadCurve2D.
    abstract double
    Returns the X coordinate of the start point indouble in precision.
    abstract double
    Returns the X coordinate of the end point indouble precision.
    abstract double
    Returns the Y coordinate of the start point indouble precision.
    abstract double
    Returns the Y coordinate of the end point indouble precision.
    boolean
    intersects(double x, double y, double w, double h)
    Tests if the interior of theShape intersects the interior of a specified rectangular area.
    boolean
    Tests if the interior of theShape intersects the interior of a specifiedRectangle2D.
    void
    setCurve(double[] coords, int offset)
    Sets the location of the end points and control points of thisQuadCurve2D to thedouble coordinates at the specified offset in the specified array.
    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 specifieddouble coordinates.
    void
    setCurve(Point2D[] pts, int offset)
    Sets the location of the end points and control points of thisQuadCurve2D to the coordinates of thePoint2D objects at the specified offset in the specified array.
    void
    Sets the location of the end points and control point of thisQuadCurve2D to the specifiedPoint2D coordinates.
    void
    Sets the location of the end points and control point of thisQuadCurve2D to the same as those in the specifiedQuadCurve2D.
    static int
    solveQuadratic(double[] eqn)
    Solves the quadratic whose coefficients are in theeqn array and places the non-complex roots back into the same array, returning the number of roots.
    static int
    solveQuadratic(double[] eqn, double[] res)
    Solves the quadratic whose coefficients are in theeqn array and places the non-complex roots into theres array, returning the number of roots.
    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 thesrc array at indicessrcoff throughsrcoff + 5 and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.
    void
    Subdivides thisQuadCurve2D and stores the resulting two subdivided curves into theleft andright curve parameters.
    static void
    Subdivides the quadratic curve specified by thesrc parameter and stores the resulting two subdivided curves into theleft andright curve 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:
  • Method Details

    • getX1

      public abstract double getX1()
      Returns the X coordinate of the start point indouble in 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 indouble precision.
      Returns:
      the Y coordinate of the start point.
      Since:
      1.2
    • getP1

      public abstract Point2D getP1()
      Returns the start point.
      Returns:
      aPoint2D that is the start point of thisQuadCurve2D.
      Since:
      1.2
    • getCtrlX

      public abstract double getCtrlX()
      Returns the X coordinate of the control point indouble precision.
      Returns:
      X coordinate the control point
      Since:
      1.2
    • getCtrlY

      public abstract double getCtrlY()
      Returns the Y coordinate of the control point indouble precision.
      Returns:
      the Y coordinate of the control point.
      Since:
      1.2
    • getCtrlPt

      public abstract Point2D getCtrlPt()
      Returns the control point.
      Returns:
      aPoint2D that is the control point of thisPoint2D.
      Since:
      1.2
    • getX2

      public abstract double getX2()
      Returns the X coordinate of the end point indouble precision.
      Returns:
      the x coordinate of the end point.
      Since:
      1.2
    • getY2

      public abstract double getY2()
      Returns the Y coordinate of the end point indouble precision.
      Returns:
      the Y coordinate of the end point.
      Since:
      1.2
    • getP2

      public abstract Point2D getP2()
      Returns the end point.
      Returns:
      aPoint object 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 specifieddouble coordinates.
      Parameters:
      x1 - the X coordinate of the start point
      y1 - the Y coordinate of the start point
      ctrlx - the X coordinate of the control point
      ctrly - the Y coordinate of the control point
      x2 - the X coordinate of the end point
      y2 - 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 thisQuadCurve2D to thedouble coordinates at the specified offset in the specified array.
      Parameters:
      coords - the array containing coordinate values
      offset - the index into the array from which to start getting the coordinate values and assigning them to thisQuadCurve2D
      Since:
      1.2
    • setCurve

      public void setCurve(Point2D p1,Point2D cp,Point2D p2)
      Sets the location of the end points and control point of thisQuadCurve2D to the specifiedPoint2D coordinates.
      Parameters:
      p1 - the start point
      cp - the control point
      p2 - the end point
      Since:
      1.2
    • setCurve

      public void setCurve(Point2D[] pts, int offset)
      Sets the location of the end points and control points of thisQuadCurve2D to the coordinates of thePoint2D objects at the specified offset in the specified array.
      Parameters:
      pts - an array containingPoint2D that define coordinate values
      offset - the index intopts from which to start getting the coordinate values and assigning them to thisQuadCurve2D
      Since:
      1.2
    • setCurve

      public void setCurve(QuadCurve2D c)
      Sets the location of the end points and control point of thisQuadCurve2D to 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 point
      y1 - the Y coordinate of the start point
      ctrlx - the X coordinate of the control point
      ctrly - the Y coordinate of the control point
      x2 - the X coordinate of the end point
      y2 - 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 point
      y1 - the Y coordinate of the start point
      ctrlx - the X coordinate of the control point
      ctrly - the Y coordinate of the control point
      x2 - the X coordinate of the end point
      y2 - 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 values
      offset - the index intocoords from 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 values
      offset - the index intocoords from 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 thisQuadCurve2D.
      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 thisQuadCurve2D.
      Since:
      1.2
    • subdivide

      public void subdivide(QuadCurve2D left,QuadCurve2D right)
      Subdivides thisQuadCurve2D and stores the resulting two subdivided curves into theleft andright curve parameters. Either or both of theleft andright objects can be the same as thisQuadCurve2D ornull.
      Parameters:
      left - theQuadCurve2D object for storing the left or first half of the subdivided curve
      right - theQuadCurve2D object for storing the right or second half of the subdivided curve
      Since:
      1.2
    • subdivide

      public static void subdivide(QuadCurve2D src,QuadCurve2D left,QuadCurve2D right)
      Subdivides the quadratic curve specified by thesrc parameter and stores the resulting two subdivided curves into theleft andright curve parameters. Either or both of theleft andright objects can be the same as thesrc object ornull.
      Parameters:
      src - the quadratic curve to be subdivided
      left - theQuadCurve2D object for storing the left or first half of the subdivided curve
      right - theQuadCurve2D object 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 thesrc array at indicessrcoff throughsrcoff + 5 and stores the resulting two subdivided curves into the two result arrays at the corresponding indices. Either or both of theleft andright arrays can benull or a reference to the same array and offset as thesrc array. 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 forleft andright and to use offsets such thatrightoff equalsleftoff + 4 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
    • solveQuadratic

      public static int solveQuadratic(double[] eqn)
      Solves the quadratic whose coefficients are in theeqn array 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 = 0
      A return value of-1 is 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-1 if the equation is a constant
      Since:
      1.2
    • solveQuadratic

      public static int solveQuadratic(double[] eqn, double[] res)
      Solves the quadratic whose coefficients are in theeqn array and places the non-complex roots into theres array, returning the number of roots. The quadratic solved is represented by the equation:
           eqn = {C, B, A};     ax^2 + bx + c = 0
      A return value of-1 is 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 equation
      res - the array that contains the non-complex roots resulting from the solution of the quadratic equation
      Returns:
      the number of roots, or-1 if 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 thedefinition of insideness.
      Specified by:
      contains in interface Shape
      Parameters:
      x - the specified X coordinate to be tested
      y - the specified Y coordinate to be tested
      Returns:
      true if the specified coordinates are inside theShape boundary;false otherwise.
      Since:
      1.2
    • contains

      public boolean contains(Point2D p)
      Tests if a specifiedPoint2D is inside the boundary of theShape, as described by the definition of insideness.
      Specified by:
      contains in interface Shape
      Parameters:
      p - the specifiedPoint2D to be tested
      Returns:
      true if the specifiedPoint2D is inside the boundary of theShape;false otherwise.
      Since:
      1.2
    • intersects

      public boolean intersects(double x, double y, double w, double h)
      Tests if the interior of theShape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect theShape if any point is contained in both the interior of theShape and the specified rectangular area.

      TheShape.intersects() method allows aShape implementation to conservatively returntrue when:

      • there is a high probability that the rectangular area and theShape intersect, but
      • the calculations to accurately determine this intersection are prohibitively expensive.
      This means that for someShapes this method might returntrue even though the rectangular area does not intersect theShape. TheArea class performs more accurate computations of geometric intersection than mostShape objects and therefore can be used if a more precise answer is required.

      Specified by:
      intersects in 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:
      true if the interior of theShape and the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;false otherwise.
      Since:
      1.2
      See Also:
    • intersects

      public boolean intersects(Rectangle2D r)
      Tests if the interior of theShape intersects the interior of a specifiedRectangle2D. TheShape.intersects() method allows aShape implementation to conservatively returntrue when:
      • there is a high probability that theRectangle2D and theShape intersect, but
      • the calculations to accurately determine this intersection are prohibitively expensive.
      This means that for someShapes this method might returntrue even though theRectangle2D does not intersect theShape. TheArea class performs more accurate computations of geometric intersection than mostShape objects and therefore can be used if a more precise answer is required.
      Specified by:
      intersects in interface Shape
      Parameters:
      r - the specifiedRectangle2D
      Returns:
      true if the interior of theShape and the interior of the specifiedRectangle2D intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;false otherwise.
      Since:
      1.2
      See Also:
    • contains

      public boolean contains(double x, double y, double w, double h)
      Tests if the interior of theShape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within theShape for the entire rectangular area to be considered contained within theShape.

      TheShape.contains() method allows aShape implementation to conservatively returnfalse when:

      • theintersect method returnstrue and
      • the calculations to determine whether or not theShape entirely contains the rectangular area are prohibitively expensive.
      This means that for someShapes this method might returnfalse even though theShape contains the rectangular area. TheArea class performs more accurate geometric computations than mostShape objects and therefore can be used if a more precise answer is required.

      Specified by:
      contains in 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:
      true if the interior of theShape entirely contains the specified rectangular area;false otherwise or, if theShape contains the rectangular area and theintersects method returnstrue and the containment calculations would be too expensive to perform.
      Since:
      1.2
      See Also:
    • contains

      public boolean contains(Rectangle2D r)
      Tests if the interior of theShape entirely contains the specifiedRectangle2D. TheShape.contains() method allows aShape implementation to conservatively returnfalse when:
      • theintersect method returnstrue and
      • the calculations to determine whether or not theShape entirely contains theRectangle2D are prohibitively expensive.
      This means that for someShapes this method might returnfalse even though theShape contains theRectangle2D. TheArea class performs more accurate geometric computations than mostShape objects and therefore can be used if a more precise answer is required.
      Specified by:
      contains in interface Shape
      Parameters:
      r - The specifiedRectangle2D
      Returns:
      true if the interior of theShape entirely contains theRectangle2D;false otherwise or, if theShape contains theRectangle2D and theintersects method returnstrue and the containment calculations would be too expensive to perform.
      Since:
      1.2
      See Also:
    • getBounds2D

      public Rectangle2D getBounds2D()
      Returns a high precision and more accurate bounding box of theShape than thegetBounds method. Note that there is no guarantee that the returnedRectangle2D is the smallest bounding box that encloses theShape, only that theShape lies entirely within the indicatedRectangle2D. The bounding box returned by this method is usually tighter than that returned by thegetBounds method and never fails due to overflow problems since the return value can be an instance of theRectangle2D that uses double precision values to store the dimensions.

      Note that thedefinition of insideness can lead to situations where points on the defining outline of theshape may not be considered contained in the returnedbounds object, but only in cases where those points are also not considered contained in the originalshape.

      If apoint is inside theshape according to thecontains(point) method, then it must be inside the returnedRectangle2D bounds object according to thecontains(point) method of thebounds. Specifically:

      shape.contains(p) requiresbounds.contains(p)

      If apoint is not inside theshape, then it might still be contained in thebounds object:

      bounds.contains(p) does not implyshape.contains(p)

      Specified by:
      getBounds2D in interface Shape
      Returns:
      an instance ofRectangle2D that is a high-precision bounding box of theShape.
      Since:
      1.2
      See Also:
    • getBounds

      public Rectangle getBounds()
      Returns an integerRectangle that completely encloses theShape. Note that there is no guarantee that the returnedRectangle is the smallest bounding box that encloses theShape, only that theShape lies entirely within the indicatedRectangle. The returnedRectangle might also fail to completely enclose theShape if theShape overflows the limited range of the integer data type. ThegetBounds2D method generally returns a tighter bounding box due to its greater flexibility in representation.

      Note that thedefinition of insideness can lead to situations where points on the defining outline of theshape may not be considered contained in the returnedbounds object, but only in cases where those points are also not considered contained in the originalshape.

      If apoint is inside theshape according to thecontains(point) method, then it must be inside the returnedRectangle bounds object according to thecontains(point) method of thebounds. Specifically:

      shape.contains(x,y) requiresbounds.contains(x,y)

      If apoint is not inside theshape, then it might still be contained in thebounds object:

      bounds.contains(x,y) does not implyshape.contains(x,y)

      Specified by:
      getBounds in interface Shape
      Returns:
      an integerRectangle that completely encloses theShape.
      Since:
      1.2
      See Also:
    • getPathIterator

      public PathIterator getPathIterator(AffineTransform at)
      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 thisQuadCurve2D class does not guarantee that modifications to the geometry of thisQuadCurve2D object do not affect any iterations of that geometry that are already in process.
      Specified by:
      getPathIterator in interface Shape
      Parameters:
      at - an optionalAffineTransform to apply to the shape boundary
      Returns:
      aPathIterator object that defines the boundary of the shape.
      Since:
      1.2
    • getPathIterator

      public PathIterator getPathIterator(AffineTransform at, double flatness)
      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 thisQuadCurve2D class does not guarantee that modifications to the geometry of thisQuadCurve2D object do not affect any iterations of that geometry that are already in process.
      Specified by:
      getPathIterator in interface Shape
      Parameters:
      at - an optionalAffineTransform to apply to the boundary of the shape
      flatness - 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:
      aPathIterator object that defines the flattened boundary of the shape.
      Since:
      1.2
    • clone

      public Object clone()
      Creates a new object of the same class and with the same contents as this object.
      Overrides:
      clone in class Object
      Returns:
      a clone of this instance.
      Throws:
      OutOfMemoryError - if there is not enough memory.
      Since:
      1.2
      See Also: