/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The <code>CubicCurve2D</code> class defines a cubic parametric curve
* segment in {@code (x,y)} coordinate space.
* <p>
* 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.
*
* @author Jim Graham
* @since 1.2
*/
/**
* A cubic parametric curve segment specified with
* {@code float} coordinates.
* @since 1.2
*/
/**
* The X coordinate of the start point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float x1;
/**
* The Y coordinate of the start point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float y1;
/**
* The X coordinate of the first control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float ctrlx1;
/**
* The Y coordinate of the first control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float ctrly1;
/**
* The X coordinate of the second control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float ctrlx2;
/**
* The Y coordinate of the second control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float ctrly2;
/**
* The X coordinate of the end point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float x2;
/**
* The Y coordinate of the end point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public float y2;
/**
* Constructs and initializes a CubicCurve with coordinates
* (0, 0, 0, 0, 0, 0, 0, 0).
* @since 1.2
*/
public Float() {
}
/**
* Constructs and initializes a {@code CubicCurve2D} from
* the specified {@code float} coordinates.
*
* @param x1 the X coordinate for the start point
* of the resulting {@code CubicCurve2D}
* @param y1 the Y coordinate for the start point
* of the resulting {@code CubicCurve2D}
* @param ctrlx1 the X coordinate for the first control point
* of the resulting {@code CubicCurve2D}
* @param ctrly1 the Y coordinate for the first control point
* of the resulting {@code CubicCurve2D}
* @param ctrlx2 the X coordinate for the second control point
* of the resulting {@code CubicCurve2D}
* @param ctrly2 the Y coordinate for the second control point
* of the resulting {@code CubicCurve2D}
* @param x2 the X coordinate for the end point
* of the resulting {@code CubicCurve2D}
* @param y2 the Y coordinate for the end point
* of the resulting {@code CubicCurve2D}
* @since 1.2
*/
{
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getX1() {
return (double) x1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getY1() {
return (double) y1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlX1() {
return (double) ctrlx1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlY1() {
return (double) ctrly1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlX2() {
return (double) ctrlx2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlY2() {
return (double) ctrly2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getX2() {
return (double) x2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getY2() {
return (double) y2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
{
}
/**
* Sets the location of the end points and control points
* of this curve to the specified {@code float} coordinates.
*
* @param x1 the X coordinate used to set the start point
* of this {@code CubicCurve2D}
* @param y1 the Y coordinate used to set the start point
* of this {@code CubicCurve2D}
* @param ctrlx1 the X coordinate used to set the first control point
* of this {@code CubicCurve2D}
* @param ctrly1 the Y coordinate used to set the first control point
* of this {@code CubicCurve2D}
* @param ctrlx2 the X coordinate used to set the second control point
* of this {@code CubicCurve2D}
* @param ctrly2 the Y coordinate used to set the second control point
* of this {@code CubicCurve2D}
* @param x2 the X coordinate used to set the end point
* of this {@code CubicCurve2D}
* @param y2 the Y coordinate used to set the end point
* of this {@code CubicCurve2D}
* @since 1.2
*/
{
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/*
* JDK 1.6 serialVersionUID
*/
}
/**
* A cubic parametric curve segment specified with
* {@code double} coordinates.
* @since 1.2
*/
/**
* The X coordinate of the start point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double x1;
/**
* The Y coordinate of the start point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double y1;
/**
* The X coordinate of the first control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double ctrlx1;
/**
* The Y coordinate of the first control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double ctrly1;
/**
* The X coordinate of the second control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double ctrlx2;
/**
* The Y coordinate of the second control point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double ctrly2;
/**
* The X coordinate of the end point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double x2;
/**
* The Y coordinate of the end point
* of the cubic curve segment.
* @since 1.2
* @serial
*/
public double y2;
/**
* Constructs and initializes a CubicCurve with coordinates
* (0, 0, 0, 0, 0, 0, 0, 0).
* @since 1.2
*/
public Double() {
}
/**
* Constructs and initializes a {@code CubicCurve2D} from
* the specified {@code double} coordinates.
*
* @param x1 the X coordinate for the start point
* of the resulting {@code CubicCurve2D}
* @param y1 the Y coordinate for the start point
* of the resulting {@code CubicCurve2D}
* @param ctrlx1 the X coordinate for the first control point
* of the resulting {@code CubicCurve2D}
* @param ctrly1 the Y coordinate for the first control point
* of the resulting {@code CubicCurve2D}
* @param ctrlx2 the X coordinate for the second control point
* of the resulting {@code CubicCurve2D}
* @param ctrly2 the Y coordinate for the second control point
* of the resulting {@code CubicCurve2D}
* @param x2 the X coordinate for the end point
* of the resulting {@code CubicCurve2D}
* @param y2 the Y coordinate for the end point
* of the resulting {@code CubicCurve2D}
* @since 1.2
*/
{
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getX1() {
return x1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getY1() {
return y1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlX1() {
return ctrlx1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlY1() {
return ctrly1;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlX2() {
return ctrlx2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getCtrlY2() {
return ctrly2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getX2() {
return x2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getY2() {
return y2;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
{
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/*
* JDK 1.6 serialVersionUID
*/
}
/**
* 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.
*
* @see java.awt.geom.CubicCurve2D.Float
* @see java.awt.geom.CubicCurve2D.Double
* @since 1.2
*/
protected CubicCurve2D() {
}
/**
* Returns the X coordinate of the start point in double precision.
* @return the X coordinate of the start point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getX1();
/**
* Returns the Y coordinate of the start point in double precision.
* @return the Y coordinate of the start point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getY1();
/**
* Returns the start point.
* @return a {@code Point2D} that is the start point of
* the {@code CubicCurve2D}.
* @since 1.2
*/
/**
* Returns the X coordinate of the first control point in double precision.
* @return the X coordinate of the first control point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getCtrlX1();
/**
* Returns the Y coordinate of the first control point in double precision.
* @return the Y coordinate of the first control point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getCtrlY1();
/**
* Returns the first control point.
* @return a {@code Point2D} that is the first control point of
* the {@code CubicCurve2D}.
* @since 1.2
*/
/**
* Returns the X coordinate of the second control point
* in double precision.
* @return the X coordinate of the second control point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getCtrlX2();
/**
* Returns the Y coordinate of the second control point
* in double precision.
* @return the Y coordinate of the second control point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getCtrlY2();
/**
* Returns the second control point.
* @return a {@code Point2D} that is the second control point of
* the {@code CubicCurve2D}.
* @since 1.2
*/
/**
* Returns the X coordinate of the end point in double precision.
* @return the X coordinate of the end point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getX2();
/**
* Returns the Y coordinate of the end point in double precision.
* @return the Y coordinate of the end point of the
* {@code CubicCurve2D}.
* @since 1.2
*/
public abstract double getY2();
/**
* Returns the end point.
* @return a {@code Point2D} that is the end point of
* the {@code CubicCurve2D}.
* @since 1.2
*/
/**
* Sets the location of the end points and control points of this curve
* to the specified double coordinates.
*
* @param x1 the X coordinate used to set the start point
* of this {@code CubicCurve2D}
* @param y1 the Y coordinate used to set the start point
* of this {@code CubicCurve2D}
* @param ctrlx1 the X coordinate used to set the first control point
* of this {@code CubicCurve2D}
* @param ctrly1 the Y coordinate used to set the first control point
* of this {@code CubicCurve2D}
* @param ctrlx2 the X coordinate used to set the second control point
* of this {@code CubicCurve2D}
* @param ctrly2 the Y coordinate used to set the second control point
* of this {@code CubicCurve2D}
* @param x2 the X coordinate used to set the end point
* of this {@code CubicCurve2D}
* @param y2 the Y coordinate used to set the end point
* of this {@code CubicCurve2D}
* @since 1.2
*/
/**
* 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.
* @param coords a double array containing coordinates
* @param offset the index of <code>coords</code> from which to begin
* setting the end points and control points of this curve
* to the coordinates contained in <code>coords</code>
* @since 1.2
*/
}
/**
* Sets the location of the end points and control points of this curve
* to the specified <code>Point2D</code> coordinates.
* @param p1 the first specified <code>Point2D</code> used to set the
* start point of this curve
* @param cp1 the second specified <code>Point2D</code> used to set the
* first control point of this curve
* @param cp2 the third specified <code>Point2D</code> used to set the
* second control point of this curve
* @param p2 the fourth specified <code>Point2D</code> used to set the
* end point of this curve
* @since 1.2
*/
}
/**
* Sets the location of the end points and control points of this curve
* to the coordinates of the <code>Point2D</code> objects at the specified
* offset in the specified array.
* @param pts an array of <code>Point2D</code> objects
* @param offset the index of <code>pts</code> from which to begin setting
* the end points and control points of this curve to the
* points contained in <code>pts</code>
* @since 1.2
*/
}
/**
* Sets the location of the end points and control points of this curve
* to the same as those in the specified <code>CubicCurve2D</code>.
* @param c the specified <code>CubicCurve2D</code>
* @since 1.2
*/
}
/**
* 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.
*
* @param x1 the X coordinate that specifies the start point
* of a {@code CubicCurve2D}
* @param y1 the Y coordinate that specifies the start point
* of a {@code CubicCurve2D}
* @param ctrlx1 the X coordinate that specifies the first control point
* of a {@code CubicCurve2D}
* @param ctrly1 the Y coordinate that specifies the first control point
* of a {@code CubicCurve2D}
* @param ctrlx2 the X coordinate that specifies the second control point
* of a {@code CubicCurve2D}
* @param ctrly2 the Y coordinate that specifies the second control point
* of a {@code CubicCurve2D}
* @param x2 the X coordinate that specifies the end point
* of a {@code CubicCurve2D}
* @param y2 the Y coordinate that specifies the end point
* of a {@code CubicCurve2D}
* @return the square of the flatness of the {@code CubicCurve2D}
* represented by the specified coordinates.
* @since 1.2
*/
}
/**
* 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.
*
* @param x1 the X coordinate that specifies the start point
* of a {@code CubicCurve2D}
* @param y1 the Y coordinate that specifies the start point
* of a {@code CubicCurve2D}
* @param ctrlx1 the X coordinate that specifies the first control point
* of a {@code CubicCurve2D}
* @param ctrly1 the Y coordinate that specifies the first control point
* of a {@code CubicCurve2D}
* @param ctrlx2 the X coordinate that specifies the second control point
* of a {@code CubicCurve2D}
* @param ctrly2 the Y coordinate that specifies the second control point
* of a {@code CubicCurve2D}
* @param x2 the X coordinate that specifies the end point
* of a {@code CubicCurve2D}
* @param y2 the Y coordinate that specifies the end point
* of a {@code CubicCurve2D}
* @return the flatness of the {@code CubicCurve2D}
* represented by the specified coordinates.
* @since 1.2
*/
}
/**
* 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.
* @param coords an array containing coordinates
* @param offset the index of <code>coords</code> from which to begin
* getting the end points and control points of the curve
* @return the square of the flatness of the <code>CubicCurve2D</code>
* specified by the coordinates in <code>coords</code> at
* the specified offset.
* @since 1.2
*/
}
/**
* 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.
* @param coords an array containing coordinates
* @param offset the index of <code>coords</code> from which to begin
* getting the end points and control points of the curve
* @return the flatness of the <code>CubicCurve2D</code>
* specified by the coordinates in <code>coords</code> at
* the specified offset.
* @since 1.2
*/
}
/**
* 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.
* @return the square of the flatness of this curve.
* @since 1.2
*/
public double getFlatnessSq() {
}
/**
* Returns the flatness of this curve. The flatness is the
* maximum distance of a control point from the line connecting the
* end points.
* @return the flatness of this curve.
* @since 1.2
*/
public double getFlatness() {
}
/**
* Subdivides 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.
* @param left the cubic curve object for storing for the left or
* first half of the subdivided curve
* @param right the cubic curve object for storing for the right or
* second half of the subdivided curve
* @since 1.2
*/
}
/**
* Subdivides the cubic curve specified by the <code>src</code> parameter
* and stores the resulting two subdivided curves into the
* <code>left</code> and <code>right</code> curve parameters.
* Either or both of the <code>left</code> and <code>right</code> objects
* may be the same as the <code>src</code> object or <code>null</code>.
* @param src the cubic curve to be subdivided
* @param left the cubic curve object for storing the left or
* first half of the subdivided curve
* @param right the cubic curve object for storing the right or
* second half of the subdivided curve
* @since 1.2
*/
}
}
}
/**
* Subdivides the cubic curve specified by the coordinates
* stored in the <code>src</code> array at indices <code>srcoff</code>
* through (<code>srcoff</code> + 7) and stores the
* resulting two subdivided curves into the two result arrays at the
* corresponding indices.
* Either or both of the <code>left</code> and <code>right</code>
* arrays may be <code>null</code> or a reference to the same array
* as the <code>src</code> 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 for <code>left</code>
* and <code>right</code> and to use offsets, such as <code>rightoff</code>
* equals (<code>leftoff</code> + 6), in order
* to avoid allocating extra storage for this common point.
* @param src the array holding the coordinates for the source curve
* @param srcoff the offset into the array of the beginning of the
* the 6 source coordinates
* @param left the array for storing the coordinates for the first
* half of the subdivided curve
* @param leftoff the offset into the array of the beginning of the
* the 6 left coordinates
* @param right the array for storing the coordinates for the second
* half of the subdivided curve
* @param rightoff the offset into the array of the beginning of the
* the 6 right coordinates
* @since 1.2
*/
}
}
}
}
}
/**
* Solves the cubic whose coefficients are in the <code>eqn</code>
* array and places the non-complex roots back into the same array,
* returning the number of roots. The solved cubic is represented
* by the equation:
* <pre>
* eqn = {c, b, a, d}
* dx^3 + ax^2 + bx + c = 0
* </pre>
* A 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.
* @param eqn an array containing coefficients for a cubic
* @return the number of roots, or -1 if the equation is a constant.
* @since 1.2
*/
}
/**
* Solve the cubic whose coefficients are in the <code>eqn</code>
* array and place the non-complex roots into the <code>res</code>
* array, 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.
* @param eqn the specified array of coefficients to use to solve
* the cubic equation
* @param res the array that contains the non-complex roots
* resulting from the solution of the cubic equation
* @return the number of roots, or -1 if the equation is a constant
* @since 1.3
*/
// From Graphics Gems:
final double d = eqn[3];
if (d == 0) {
}
/* normal form: x^3 + Ax^2 + Bx + C = 0 */
final double A = eqn[2] / d;
final double B = eqn[1] / d;
final double C = eqn[0] / d;
// substitute x = y - A/3 to eliminate quadratic term:
// x^3 +Px + Q = 0
//
// Since we actually need P/3 and Q/2 for all of the
// calculations that follow, we will calculate
// p = P/3
// q = Q/2
// instead and use those values for simplicity of the code.
double sq_A = A * A;
/* use Cardano's formula */
double cb_p = p * p * p;
double D = q * q + cb_p;
int num;
if (D < 0) { /* Casus irreducibilis: three real solutions */
// see: http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method
}
num = 3;
for (int i = 0; i < num; ++i) {
}
} else {
// Please see the comment in fixRoots marked 'XXX' before changing
// any of the code in this case.
double uv = u+v;
num = 1;
}
num = 2;
}
// this must be done after the potential Arrays.copyOf
}
}
num--;
}
}
return num;
}
// preconditions: eqn != res && eqn[3] != 0 && num > 1
// This method tries to improve the accuracy of the roots of eqn (which
// should be in res). It also might eliminate roots in res if it decideds
// that they're not real roots. It will not check for roots that the
// computation of res might have missed, so this method should only be
// used when the roots in res have been computed using an algorithm
// that never underestimates the number of roots (such as solveCubic above)
critCount--;
}
}
// below we use critCount to possibly filter out roots that shouldn't
// have been computed. We require that eqn[3] != 0, so eqn is a proper
// cubic, which means that its limits at -/+inf are -/+inf or +/-inf.
// Therefore, if critCount==2, the curve is shaped like a sideways S,
// and it could have 1-3 roots. If critCount==0 it is monotonic, and
// if critCount==1 it is monotonic with a single point where it is
// flat. In the last 2 cases there can only be 1 root. So in cases
// where num > 1 but critCount < 2, we eliminate all roots in res
// except one.
if (num == 3) {
if (critCount == 2) {
// this just tries to improve the accuracy of the computed
// roots using Newton's method.
return 3;
} else if (critCount == 1) {
// we only need fx0 and fxe for the sign of the polynomial
// at -inf and +inf respectively, so we don't need to do
// fx0 = solveEqn(eqn, 3, x0); fxe = solveEqn(eqn, 3, xe)
// if critCount == 1 or critCount == 0, but num == 3 then
// something has gone wrong. This branch and the one below
// would ideally never execute, but if they do we can't know
// which of the computed roots is closest to the real root;
// therefore, we can't use refineRootWithHint. But even if
// we did know, being here most likely means that the
// curve is very flat close to two of the computed roots
// (or maybe even all three). This might make Newton's method
// fail altogether, which would be a pain to detect and fix.
// This is why we use a very stable bisection method.
} else /* fx1 must be 0 */ {
}
// return 1
} else if (critCount == 0) {
// return 1
}
// XXX: here we assume that res[0] has better accuracy than res[1].
// This is true because this method is only used from solveCubic
// which puts in res[0] the root that it would compute anyway even
// if num==1. If this method is ever used from any other method, or
// if the solveCubic implementation changes, this assumption should
// be reevaluated, and the choice of goodRoot might have to become
// goodRoot = (abs(eqn'(res[0])) > abs(eqn'(res[1]))) ? res[0] : res[1]
// where eqn' is the derivative of eqn.
// If a cubic curve really has 2 roots, one of those roots must be
// at a critical point. That can't be goodRoot, so we compute x to
// be the farthest critical point from goodRoot. If there are two
// roots, x must be the second one, so we evaluate eqn at x, and if
// it is zero (or close enough) we put x in res[1] (or badRoot, if
// |solveEqn(eqn, 3, badRoot)| < |solveEqn(eqn, 3, x)| but this
// shouldn't happen often).
return 2;
}
} // else there can only be one root - goodRoot, and it is already in res[0]
return 1;
}
// use newton's method.
return t;
}
double origt = t;
for (int i = 0; i < 3; i++) {
break;
}
t = newt;
}
return t;
}
return origt;
}
return x02;
}
delta1 /= 64;
delta2 /= 64;
}
if (fx02 == 0) {
return x02;
}
if (fxe2 == 0) {
return xe2;
}
}
if (fm == 0) {
return m;
}
xe = m;
} else {
x0 = m;
}
}
return m;
}
}
double d = y - x;
}
}
}
while (--order >= 0) {
}
return v;
}
/*
* Computes M+1 where M is an upper bound for all the roots in of eqn.
* See: http://en.wikipedia.org/wiki/Sturm%27s_theorem#Applications.
* The above link doesn't contain a proof, but I [dlila] proved it myself
* so the result is reliable. The proof isn't difficult, but it's a bit
* long to include here.
* Precondition: eqn must represent a cubic polynomial
*/
double d = eqn[3];
double a = eqn[2];
double b = eqn[1];
double c = eqn[0];
M += ulp(M) + 1;
return M;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean contains(double x, double y) {
if (!(x * 0.0 + y * 0.0 == 0.0)) {
/* Either x or y was infinite or NaN.
* A NaN always produces a negative response to any test
* and Infinity values cannot be "inside" any path so
* they should return false as well.
*/
return false;
}
// We count the "Y" crossings to determine if the point is
// inside the curve bounded by its closing line.
int crossings =
Curve.pointCrossingsForCubic(x, y,
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean intersects(double x, double y, double w, double h) {
// Trivially reject non-existant rectangles
if (w <= 0 || h <= 0) {
return false;
}
int numCrossings = rectCrossings(x, y, w, h);
// the intended return value is
// numCrossings != 0 || numCrossings == Curve.RECT_INTERSECTS
// but if (numCrossings != 0) numCrossings == INTERSECTS won't matter
// and if !(numCrossings != 0) then numCrossings == 0, so
// numCrossings != RECT_INTERSECT
return numCrossings != 0;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean contains(double x, double y, double w, double h) {
if (w <= 0 || h <= 0) {
return false;
}
int numCrossings = rectCrossings(x, y, w, h);
}
private int rectCrossings(double x, double y, double w, double h) {
int crossings = 0;
x, y,
x+w, y+h,
return crossings;
}
}
// we call this with the curve's direction reversed, because we wanted
// to call rectCrossingsForLine first, because it's cheaper.
x, y,
x+w, y+h,
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
return getBounds2D().getBounds();
}
/**
* Returns an iteration object that defines the boundary of the
* shape.
* The iterator for this class is not multi-threaded safe,
* which means that this <code>CubicCurve2D</code> class does not
* guarantee that modifications to the geometry of this
* <code>CubicCurve2D</code> object do not affect any iterations of
* that geometry that are already in process.
* @param at an optional <code>AffineTransform</code> to be applied to the
* coordinates as they are returned in the iteration, or <code>null</code>
* if untransformed coordinates are desired
* @return the <code>PathIterator</code> object that returns the
* geometry of the outline of this <code>CubicCurve2D</code>, one
* segment at a time.
* @since 1.2
*/
return new CubicIterator(this, at);
}
/**
* Return an iteration object that defines the boundary of the
* flattened shape.
* The iterator for this class is not multi-threaded safe,
* which means that this <code>CubicCurve2D</code> class does not
* guarantee that modifications to the geometry of this
* <code>CubicCurve2D</code> object do not affect any iterations of
* that geometry that are already in process.
* @param at an optional <code>AffineTransform</code> to be applied to the
* coordinates as they are returned in the iteration, or <code>null</code>
* if untransformed coordinates are desired
* @param 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
* @return the <code>PathIterator</code> object that returns the
* geometry of the outline of this <code>CubicCurve2D</code>,
* one segment at a time.
* @since 1.2
*/
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since 1.2
*/
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
}