FileDocCategorySizeDatePackage
QuadCurve2D.javaAPI DocAndroid 1.5 API30613Wed May 06 22:41:54 BST 2009java.awt.geom

QuadCurve2D

public abstract class QuadCurve2D extends Object implements Shape, Cloneable
The Class QuadCurve2D is a Shape that represents a segment of a quadratic (Bezier) curve. The curved segment is determined by three points: a start point, an end point, and a control point. The line from the control point to the starting point gives the tangent to the curve at the starting point, and the line from the control point to the end point gives the tangent to the curve at the end point.
since
Android 1.0

Fields Summary
Constructors Summary
protected QuadCurve2D()
Instantiates a new quadratic curve.

    
Methods Summary
public java.lang.Objectclone()

        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new InternalError();
        }
    
public booleancontains(double px, double py)

        return Crossing.isInsideEvenOdd(Crossing.crossShape(this, px, py));
    
public booleancontains(double rx, double ry, double rw, double rh)

        int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
        return cross != Crossing.CROSSING && Crossing.isInsideEvenOdd(cross);
    
public booleancontains(java.awt.geom.Point2D p)

        return contains(p.getX(), p.getY());
    
public booleancontains(java.awt.geom.Rectangle2D r)

        return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public java.awt.RectanglegetBounds()

        return getBounds2D().getBounds();
    
public abstract java.awt.geom.Point2DgetCtrlPt()
Gets the control point.

return
the control point.

public abstract doublegetCtrlX()
Gets the x coordinate of the control point.

return
the x coordinate of the control point.

public abstract doublegetCtrlY()
Gets the y coordinate of the control point.

return
y coordinate of the control point.

public doublegetFlatness()
Gets the distance from the control point to the straight line segment connecting the start point and the end point of this QuadCurve2D.

return
the the distance from the control point to the straight line segment connecting the start point and the end point of this QuadCurve2D.

        return Line2D.ptSegDist(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY());
    
public static doublegetFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Gets the distance from the control point to the straight line segment connecting the start point and the end point.

param
x1 the x coordinate of the starting point of the curved segment.
param
y1 the y coordinate of the starting point of the curved segment.
param
ctrlx the x coordinate of the control point.
param
ctrly the y coordinate of the control point.
param
x2 the x coordinate of the end point of the curved segment.
param
y2 the y coordinate of the end point of the curved segment.
return
the the distance from the control point to the straight line segment connecting the start point and the end point.

        return Line2D.ptSegDist(x1, y1, x2, y2, ctrlx, ctrly);
    
public static doublegetFlatness(double[] coords, int offset)
Gets the the distance from the control point to the straight line segment connecting the start point and the end point. The values are read in the same order as the arguments of the method {@link QuadCurve2D#getFlatness(double, double, double, double, double, double)} .

param
coords the array of points containing the coordinates to use for the calculation.
param
offset the offset of the data to read within the array.
return
the the distance from the control point to the straight line segment connecting the start point and the end point.
throws
ArrayIndexOutOfBoundsException if {code coords.length} < offset + 6.
throws
NullPointerException if the coordinate array is null.

        return Line2D.ptSegDist(coords[offset + 0], coords[offset + 1], coords[offset + 4],
                coords[offset + 5], coords[offset + 2], coords[offset + 3]);
    
public doublegetFlatnessSq()
Gets the square of the distance from the control point to the straight line segment connecting the start point and the end point for this curve.

return
the square of the distance from the control point to the straight line segment connecting the start point and the end point.

        return Line2D.ptSegDistSq(getX1(), getY1(), getX2(), getY2(), getCtrlX(), getCtrlY());
    
public static doublegetFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Gets the square of the distance from the control point to the straight line segment connecting the start point and the end point.

param
x1 the x coordinate of the starting point of the curved segment.
param
y1 the y coordinate of the starting point of the curved segment.
param
ctrlx the x coordinate of the control point.
param
ctrly the y coordinate of the control point.
param
x2 the x coordinate of the end point of the curved segment.
param
y2 the y coordinate of the end point of the curved segment.
return
the square of the distance from the control point to the straight line segment connecting the start point and the end point.

        return Line2D.ptSegDistSq(x1, y1, x2, y2, ctrlx, ctrly);
    
public static doublegetFlatnessSq(double[] coords, int offset)
Gets the square of the distance from the control point to the straight line segment connecting the start point and the end point by reading the coordinates of the points from an array of values. The values are read in the same order as the arguments of the method {@link QuadCurve2D#getFlatnessSq(double, double, double, double, double, double)} .

param
coords the array of points containing the coordinates to use for the calculation
param
offset the offset of the data to read within the array
return
the square of the distance from the control point to the straight line segment connecting the start point and the end point.
throws
ArrayIndexOutOfBoundsException if {@code coords.length} < offset + 6.
throws
NullPointerException if the coordinate array is null.

        return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], coords[offset + 4],
                coords[offset + 5], coords[offset + 2], coords[offset + 3]);
    
public abstract java.awt.geom.Point2DgetP1()
Gets the starting point.

return
the starting point.

public abstract java.awt.geom.Point2DgetP2()
Gets the end point.

return
the end point.

public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform t)

        return new Iterator(this, t);
    
public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform t, double flatness)

        return new FlatteningPathIterator(getPathIterator(t), flatness);
    
public abstract doublegetX1()
Gets the x coordinate of the starting point.

return
the x coordinate of the starting point.

public abstract doublegetX2()
Gets the x coordinate of the end point.

return
the x coordinate of the end point.

public abstract doublegetY1()
Gets the y coordinate of the starting point.

return
the y coordinate of the starting point.

public abstract doublegetY2()
Gets the y coordinate of the end point.

return
the y coordinate of the end point.

public booleanintersects(double rx, double ry, double rw, double rh)

        int cross = Crossing.intersectShape(this, rx, ry, rw, rh);
        return cross == Crossing.CROSSING || Crossing.isInsideEvenOdd(cross);
    
public booleanintersects(java.awt.geom.Rectangle2D r)

        return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public abstract voidsetCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Sets the data of the curve.

param
x1 the x coordinate of the starting point of the curved segment.
param
y1 the y coordinate of the starting point of the curved segment.
param
ctrlx the x coordinate of the control point.
param
ctrly the y coordinate of the control point.
param
x2 the x coordinate of the end point of the curved segment.
param
y2 the y coordinate of the end point of the curved segment.

public voidsetCurve(java.awt.geom.Point2D p1, java.awt.geom.Point2D cp, java.awt.geom.Point2D p2)
Sets the data of the curve.

param
p1 the starting point of the curved segment.
param
cp the control point.
param
p2 the end point of the curved segment.
throws
NullPointerException if any of the three points is null.

        setCurve(p1.getX(), p1.getY(), cp.getX(), cp.getY(), p2.getX(), p2.getY());
    
public voidsetCurve(double[] coords, int offset)
Sets the data of the curve by reading the data from an array of values. The values are read in the same order as the arguments of the method {@link QuadCurve2D#setCurve(double, double, double, double, double, double)} .

param
coords the array of values containing the new coordinates.
param
offset the offset of the data to read within the array.
throws
ArrayIndexOutOfBoundsException if {@code coords.length} < offset + 6.
throws
NullPointerException if the coordinate array is null.

        setCurve(coords[offset + 0], coords[offset + 1], coords[offset + 2], coords[offset + 3],
                coords[offset + 4], coords[offset + 5]);
    
public voidsetCurve(java.awt.geom.Point2D[] points, int offset)
Sets the data of the curve by reading the data from an array of points. The values are read in the same order as the arguments of the method {@link QuadCurve2D#setCurve(Point2D, Point2D, Point2D)}.

param
points the array of points containing the new coordinates.
param
offset the offset of the data to read within the array.
throws
ArrayIndexOutOfBoundsException if points.length < offset + 3.
throws
NullPointerException if the point array is null.

        setCurve(points[offset + 0].getX(), points[offset + 0].getY(), points[offset + 1].getX(),
                points[offset + 1].getY(), points[offset + 2].getX(), points[offset + 2].getY());
    
public voidsetCurve(java.awt.geom.QuadCurve2D curve)
Sets the data of the curve by copying it from another QuadCurve2D.

param
curve the curve to copy the data points from.
throws
NullPointerException if the curve is null.

        setCurve(curve.getX1(), curve.getY1(), curve.getCtrlX(), curve.getCtrlY(), curve.getX2(),
                curve.getY2());
    
public static intsolveQuadratic(double[] eqn)
Finds the roots of the quadratic polynomial. This is accomplished by finding the (real) values of x that solve the following equation: eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written back into the array eqn starting from the index 0 in the array. The return value tells how many array elements have been changed by this method call.

param
eqn an array containing the coefficients of the quadratic polynomial to solve.
return
the number of roots of the quadratic polynomial.
throws
ArrayIndexOutOfBoundsException if {@code eqn.length} < 3.
throws
NullPointerException if the array is null.

        return solveQuadratic(eqn, eqn);
    
public static intsolveQuadratic(double[] eqn, double[] res)
Finds the roots of the quadratic polynomial. This is accomplished by finding the (real) values of x that solve the following equation: eqn[2]*x*x + eqn[1]*x + eqn[0] = 0. The solutions are written into the array res starting from the index 0 in the array. The return value tells how many array elements have been written by this method call.

param
eqn an array containing the coefficients of the quadratic polynomial to solve.
param
res the array that this method writes the results into.
return
the number of roots of the quadratic polynomial.
throws
ArrayIndexOutOfBoundsException if {@code eqn.length} < 3 or if {@code res.length} is less than the number of roots.
throws
NullPointerException if either array is null.

        return Crossing.solveQuad(eqn, res);
    
public voidsubdivide(java.awt.geom.QuadCurve2D left, java.awt.geom.QuadCurve2D right)
Creates the data for two quadratic curves by dividing this curve in two. The division point is the point on the curve that is closest to this curve's control point. The data of this curve is left unchanged.

param
left the QuadCurve2D where the left (start) segment's data is written.
param
right the QuadCurve2D where the right (end) segment's data is written.
throws
NullPointerException if either curve is null.

        subdivide(this, left, right);
    
public static voidsubdivide(java.awt.geom.QuadCurve2D src, java.awt.geom.QuadCurve2D left, java.awt.geom.QuadCurve2D right)
Creates the data for two quadratic curves by dividing a source curve in two. The division point is the point on the curve that is closest to the source curve's control point. The data of the source curve is left unchanged.

param
src the curve that provides the initial data.
param
left the QuadCurve2D where the left (start) segment's data is written.
param
right the QuadCurve2D where the right (end) segment's data is written.
throws
NullPointerException if one of the curves is null.

        double x1 = src.getX1();
        double y1 = src.getY1();
        double cx = src.getCtrlX();
        double cy = src.getCtrlY();
        double x2 = src.getX2();
        double y2 = src.getY2();
        double cx1 = (x1 + cx) / 2.0;
        double cy1 = (y1 + cy) / 2.0;
        double cx2 = (x2 + cx) / 2.0;
        double cy2 = (y2 + cy) / 2.0;
        cx = (cx1 + cx2) / 2.0;
        cy = (cy1 + cy2) / 2.0;
        if (left != null) {
            left.setCurve(x1, y1, cx1, cy1, cx, cy);
        }
        if (right != null) {
            right.setCurve(cx, cy, cx2, cy2, x2, y2);
        }
    
public static voidsubdivide(double[] src, int srcoff, double[] left, int leftOff, double[] right, int rightOff)
Creates the data for two quadratic curves by dividing a source curve in two. The division point is the point on the curve that is closest to the source curve's control point. The data for the three curves is read and written from arrays of values in the usual order: x1, y1, cx, cy, x2, y2.

param
src the array that gives the data values for the source curve.
param
srcoff the offset in the src array to read the values from.
param
left the array where the coordinates of the start curve should be written.
param
leftOff the offset in the left array to start writing the values.
param
right the array where the coordinates of the end curve should be written.
param
rightOff the offset in the right array to start writing the values.
throws
ArrayIndexOutOfBoundsException if {@code src.length} < srcoff + 6 or if {@code left.length} < leftOff + 6 or if {@code right.length} < rightOff + 6.
throws
NullPointerException if one of the arrays is null.

        double x1 = src[srcoff + 0];
        double y1 = src[srcoff + 1];
        double cx = src[srcoff + 2];
        double cy = src[srcoff + 3];
        double x2 = src[srcoff + 4];
        double y2 = src[srcoff + 5];
        double cx1 = (x1 + cx) / 2.0;
        double cy1 = (y1 + cy) / 2.0;
        double cx2 = (x2 + cx) / 2.0;
        double cy2 = (y2 + cy) / 2.0;
        cx = (cx1 + cx2) / 2.0;
        cy = (cy1 + cy2) / 2.0;
        if (left != null) {
            left[leftOff + 0] = x1;
            left[leftOff + 1] = y1;
            left[leftOff + 2] = cx1;
            left[leftOff + 3] = cy1;
            left[leftOff + 4] = cx;
            left[leftOff + 5] = cy;
        }
        if (right != null) {
            right[rightOff + 0] = cx;
            right[rightOff + 1] = cy;
            right[rightOff + 2] = cx2;
            right[rightOff + 3] = cy2;
            right[rightOff + 4] = x2;
            right[rightOff + 5] = y2;
        }