public class CubicCurve2D extends Shape
CubicCurve2D
class defines a cubic parametric curve
segment in (x,y)
coordinate space.
This class is only the abstract superclass for all objects which store a 2D cubic curve segment. The actual storage representation of the coordinates is left to the subclass.
Modifier and Type | Field and Description |
---|---|
private static int |
ABOVE |
private static int |
BELOW |
float |
ctrlx1
The X coordinate of the first control point
of the cubic curve segment.
|
float |
ctrlx2
The X coordinate of the second control point
of the cubic curve segment.
|
float |
ctrly1
The Y coordinate of the first control point
of the cubic curve segment.
|
float |
ctrly2
The Y coordinate of the second control point
of the cubic curve segment.
|
private static int |
HIGHEDGE |
private static int |
INSIDE |
private static int |
LOWEDGE |
float |
x1
The X coordinate of the start point
of the cubic curve segment.
|
float |
x2
The X coordinate of the end point
of the cubic curve segment.
|
float |
y1
The Y coordinate of the start point
of the cubic curve segment.
|
float |
y2
The Y coordinate of the end point
of the cubic curve segment.
|
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP, RECT_INTERSECTS
Constructor and Description |
---|
CubicCurve2D()
Constructs and initializes a CubicCurve with coordinates
(0, 0, 0, 0, 0, 0, 0, 0).
|
CubicCurve2D(float x1,
float y1,
float ctrlx1,
float ctrly1,
float ctrlx2,
float ctrly2,
float x2,
float y2)
Constructs and initializes a
CubicCurve2D from
the specified float coordinates. |
Modifier and Type | Method and Description |
---|---|
private float |
calcX(float t) |
private float |
calcY(float t) |
boolean |
contains(float x,
float y)
Tests if the specified coordinates are inside the boundary of the
Shape . |
boolean |
contains(float x,
float y,
float w,
float h)
Tests if the interior of the
Shape entirely contains
the specified rectangular area. |
boolean |
contains(Point2D p)
Tests if a specified
Point2D is inside the boundary
of the Shape . |
CubicCurve2D |
copy()
Returns a new copy of this
Shape instance. |
boolean |
equals(java.lang.Object obj) |
Point2D |
eval(float t)
Evaluates this cubic curve at the given parameter value, where
it is expected, but not required, that the parameter will be
between 0 and 1.
|
void |
eval(float td,
Point2D result)
Evaluates this cubic curve at the given parameter value, where
it is expected, but not required, that the parameter will be
between 0 and 1.
|
private static int |
evalCubic(float[] vals,
int num,
boolean include0,
boolean include1,
float[] inflect,
float c1,
float cp1,
float cp2,
float c2) |
Point2D |
evalDt(float t)
Evaluates the derivative of this cubic curve at the given
parameter value, where it is expected, but not required, that
the parameter will be between 0 and 1.
|
void |
evalDt(float td,
Point2D result)
Evaluates the derivative of this cubic curve at the given
parameter value, where it is expected, but not required, that
the parameter will be between 0 and 1.
|
private static void |
fillEqn(float[] eqn,
float val,
float c1,
float cp1,
float cp2,
float c2) |
private static float |
findZero(float t,
float target,
float[] eqn) |
private static void |
fixRoots(float[] res,
float[] eqn) |
RectBounds |
getBounds()
Note that there is no guarantee that the returned
RectBounds is the smallest bounding box that encloses
the Shape , only that the Shape lies
entirely within the indicated RectBounds . |
float |
getFlatness()
Returns the flatness of this curve.
|
static float |
getFlatness(float[] coords,
int offset)
Returns the flatness of the cubic curve specified
by the control points stored in the indicated array at the
indicated index.
|
static float |
getFlatness(float x1,
float y1,
float ctrlx1,
float ctrly1,
float ctrlx2,
float ctrly2,
float x2,
float y2)
Returns the flatness of the cubic curve specified
by the indicated control points.
|
float |
getFlatnessSq()
Returns the square of the flatness of this curve.
|
static float |
getFlatnessSq(float[] coords,
int offset)
Returns the square of the flatness of the cubic curve specified
by the control points stored in the indicated array at the
indicated index.
|
static float |
getFlatnessSq(float x1,
float y1,
float ctrlx1,
float ctrly1,
float ctrlx2,
float ctrly2,
float x2,
float y2)
Returns the square of the flatness of the cubic curve specified
by the indicated control points.
|
PathIterator |
getPathIterator(BaseTransform tx)
Returns an iteration object that defines the boundary of the
shape.
|
PathIterator |
getPathIterator(BaseTransform tx,
float flatness)
Return an iteration object that defines the boundary of the
flattened shape.
|
private static int |
getTag(float coord,
float low,
float high) |
int |
hashCode() |
boolean |
intersects(float x,
float y,
float w,
float h)
Tests if the interior of the
Shape intersects the
interior of a specified rectangular area. |
private static boolean |
inwards(int pttag,
int opt1tag,
int opt2tag) |
void |
setCurve(CubicCurve2D c)
Sets the location of the end points and control points of this curve
to the same as those in the specified
CubicCurve2D . |
void |
setCurve(float[] coords,
int offset)
Sets the location of the end points and control points of this curve
to the double coordinates at the specified offset in the specified
array.
|
void |
setCurve(float x1,
float y1,
float ctrlx1,
float ctrly1,
float ctrlx2,
float ctrly2,
float x2,
float y2)
Sets the location of the end points and control points
of this curve to the specified
float coordinates. |
void |
setCurve(Point2D[] pts,
int offset)
Sets the location of the end points and control points of this curve
to the coordinates of the
Point2D objects at the specified
offset in the specified array. |
void |
setCurve(Point2D p1,
Point2D cp1,
Point2D cp2,
Point2D p2)
Sets the location of the end points and control points of this curve
to the specified
Point2D coordinates. |
static int |
solveCubic(float[] eqn)
Solves the cubic whose coefficients are in the
eqn
array and places the non-complex roots back into the same array,
returning the number of roots. |
static int |
solveCubic(float[] eqn,
float[] res)
Solve the cubic whose coefficients are in the
eqn
array and place the non-complex roots into the res
array, returning the number of roots. |
private static float |
solveEqn(float[] eqn,
int order,
float t) |
void |
subdivide(CubicCurve2D left,
CubicCurve2D right)
Subdivides this cubic curve and stores the resulting two
subdivided curves into the left and right curve parameters.
|
static void |
subdivide(CubicCurve2D src,
CubicCurve2D left,
CubicCurve2D right)
Subdivides the cubic curve specified by the
src parameter
and stores the resulting two subdivided curves into the
left and right curve parameters. |
static void |
subdivide(float[] src,
int srcoff,
float[] left,
int leftoff,
float[] right,
int rightoff)
Subdivides the cubic curve specified by the coordinates
stored in the
src array at indices srcoff
through (srcoff + 7) and stores the
resulting two subdivided curves into the two result arrays at the
corresponding indices. |
void |
subdivide(float t,
CubicCurve2D left,
CubicCurve2D right)
Subdivides this cubic curve at the given parameter value
(expected to be between 0 and 1) and stores the resulting two
subdivided curves into the left and right curve parameters.
|
accumulate, accumulateCubic, accumulateCubic, accumulateQuad, contains, intersects, intersectsLine, outcode, pointCrossingsForCubic, pointCrossingsForLine, pointCrossingsForPath, pointCrossingsForQuad, rectCrossingsForCubic, rectCrossingsForLine, rectCrossingsForPath, rectCrossingsForQuad
public float x1
public float y1
public float ctrlx1
public float ctrly1
public float ctrlx2
public float ctrly2
public float x2
public float y2
private static final int BELOW
private static final int LOWEDGE
private static final int INSIDE
private static final int HIGHEDGE
private static final int ABOVE
public CubicCurve2D()
public CubicCurve2D(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2)
CubicCurve2D
from
the specified float
coordinates.x1
- the X coordinate for the start point
of the resulting CubicCurve2D
y1
- the Y coordinate for the start point
of the resulting CubicCurve2D
ctrlx1
- the X coordinate for the first control point
of the resulting CubicCurve2D
ctrly1
- the Y coordinate for the first control point
of the resulting CubicCurve2D
ctrlx2
- the X coordinate for the second control point
of the resulting CubicCurve2D
ctrly2
- the Y coordinate for the second control point
of the resulting CubicCurve2D
x2
- the X coordinate for the end point
of the resulting CubicCurve2D
y2
- the Y coordinate for the end point
of the resulting CubicCurve2D
public void setCurve(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2)
float
coordinates.x1
- the X coordinate used to set the start point
of this CubicCurve2D
y1
- the Y coordinate used to set the start point
of this CubicCurve2D
ctrlx1
- the X coordinate used to set the first control point
of this CubicCurve2D
ctrly1
- the Y coordinate used to set the first control point
of this CubicCurve2D
ctrlx2
- the X coordinate used to set the second control point
of this CubicCurve2D
ctrly2
- the Y coordinate used to set the second control point
of this CubicCurve2D
x2
- the X coordinate used to set the end point
of this CubicCurve2D
y2
- the Y coordinate used to set the end point
of this CubicCurve2D
public RectBounds getBounds()
RectBounds
is the smallest bounding box that encloses
the Shape
, only that the Shape
lies
entirely within the indicated RectBounds
.public Point2D eval(float t)
t
- parameter value at which to evaluate the curvepublic void eval(float td, Point2D result)
td
- parameter value at which to evaluate the curveresult
- Point2D in to which to store the evaluation of
the curve at that parameter valuepublic Point2D evalDt(float t)
t
- parameter value at which to compute the derivative of
the curvepublic void evalDt(float td, Point2D result)
t
- parameter value at which to compute the derivative of
the curveresult
- Point2D in to which to store the derivative of
the curve at that parameter valuepublic void setCurve(float[] coords, int offset)
coords
- a double array containing coordinatesoffset
- the index of coords
from which to begin
setting the end points and control points of this curve
to the coordinates contained in coords
public void setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2)
Point2D
coordinates.p1
- the first specified Point2D
used to set the
start point of this curvecp1
- the second specified Point2D
used to set the
first control point of this curvecp2
- the third specified Point2D
used to set the
second control point of this curvep2
- the fourth specified Point2D
used to set the
end point of this curvepublic void setCurve(Point2D[] pts, int offset)
Point2D
objects at the specified
offset in the specified array.pts
- an array of Point2D
objectsoffset
- the index of pts
from which to begin setting
the end points and control points of this curve to the
points contained in pts
public void setCurve(CubicCurve2D c)
CubicCurve2D
.c
- the specified CubicCurve2D
public static float getFlatnessSq(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2)
x1
- the X coordinate that specifies the start point
of a CubicCurve2D
y1
- the Y coordinate that specifies the start point
of a CubicCurve2D
ctrlx1
- the X coordinate that specifies the first control point
of a CubicCurve2D
ctrly1
- the Y coordinate that specifies the first control point
of a CubicCurve2D
ctrlx2
- the X coordinate that specifies the second control point
of a CubicCurve2D
ctrly2
- the Y coordinate that specifies the second control point
of a CubicCurve2D
x2
- the X coordinate that specifies the end point
of a CubicCurve2D
y2
- the Y coordinate that specifies the end point
of a CubicCurve2D
CubicCurve2D
represented by the specified coordinates.public static float getFlatness(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2)
x1
- the X coordinate that specifies the start point
of a CubicCurve2D
y1
- the Y coordinate that specifies the start point
of a CubicCurve2D
ctrlx1
- the X coordinate that specifies the first control point
of a CubicCurve2D
ctrly1
- the Y coordinate that specifies the first control point
of a CubicCurve2D
ctrlx2
- the X coordinate that specifies the second control point
of a CubicCurve2D
ctrly2
- the Y coordinate that specifies the second control point
of a CubicCurve2D
x2
- the X coordinate that specifies the end point
of a CubicCurve2D
y2
- the Y coordinate that specifies the end point
of a CubicCurve2D
CubicCurve2D
represented by the specified coordinates.public static float getFlatnessSq(float[] coords, int offset)
coords
- an array containing coordinatesoffset
- the index of coords
from which to begin
getting the end points and control points of the curveCubicCurve2D
specified by the coordinates in coords
at
the specified offset.public static float getFlatness(float[] coords, int offset)
coords
- an array containing coordinatesoffset
- the index of coords
from which to begin
getting the end points and control points of the curveCubicCurve2D
specified by the coordinates in coords
at
the specified offset.public float getFlatnessSq()
public float getFlatness()
public void subdivide(float t, CubicCurve2D left, CubicCurve2D right)
t
- the parameter value at which to subdivide the curveleft
- the cubic curve object for storing for the left or
first portion of the subdivided curveright
- the cubic curve object for storing for the right or
second portion of the subdivided curvepublic void subdivide(CubicCurve2D left, CubicCurve2D right)
left
- the cubic curve object for storing for the left or
first half of the subdivided curveright
- the cubic curve object for storing for the right or
second half of the subdivided curvepublic static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right)
src
parameter
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 the src
object or null
.src
- the cubic curve to be subdividedleft
- the cubic curve object for storing the left or
first half of the subdivided curveright
- the cubic curve object for storing the right or
second half of the subdivided curvepublic static void subdivide(float[] src, int srcoff, float[] left, int leftoff, float[] right, int rightoff)
src
array at indices srcoff
through (srcoff
+ 7) and stores the
resulting two subdivided curves into the two result arrays at the
corresponding indices.
Either or both of the left
and right
arrays may be null
or a reference to the same array
as the src
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 left
and right
and to use offsets, such as rightoff
equals (leftoff
+ 6), in order
to avoid allocating extra storage for this common point.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 coordinatespublic static int solveCubic(float[] eqn)
eqn
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:
eqn = {c, b, a, d} dx^3 + ax^2 + bx + c = 0A return value of -1 is used to distinguish a constant equation that might be always 0 or never 0 from an equation that has no zeroes.
eqn
- an array containing coefficients for a cubicpublic static int solveCubic(float[] eqn, float[] res)
eqn
array and place the non-complex roots into the res
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.eqn
- the specified array of coefficients to use to solve
the cubic equationres
- the array that contains the non-complex roots
resulting from the solution of the cubic equationprivate static void fixRoots(float[] res, float[] eqn)
private static float solveEqn(float[] eqn, int order, float t)
private static float findZero(float t, float target, float[] eqn)
public boolean contains(float x, float y)
Shape
.public boolean contains(Point2D p)
Point2D
is inside the boundary
of the Shape
.private static void fillEqn(float[] eqn, float val, float c1, float cp1, float cp2, float c2)
private static int evalCubic(float[] vals, int num, boolean include0, boolean include1, float[] inflect, float c1, float cp1, float cp2, float c2)
private static int getTag(float coord, float low, float high)
private static boolean inwards(int pttag, int opt1tag, int opt2tag)
public boolean intersects(float x, float y, float w, float h)
Shape
intersects the
interior of a specified rectangular area.
The rectangular area is considered to intersect the Shape
if any point is contained in both the interior of the
Shape
and the specified rectangular area.
The Shape.intersects()
method allows a Shape
implementation to conservatively return true
when:
Shape
intersect, but
Shapes
this method might
return true
even though the rectangular area does not
intersect the Shape
.
The Area
class performs
more accurate computations of geometric intersection than most
Shape
objects and therefore can be used if a more precise
answer is required.intersects
in class Shape
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 areatrue
if the interior of the Shape
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.public boolean contains(float x, float y, float w, float h)
Shape
entirely contains
the specified rectangular area. All coordinates that lie inside
the rectangular area must lie within the Shape
for the
entire rectanglar area to be considered contained within the
Shape
.
The Shape.contains()
method allows a Shape
implementation to conservatively return false
when:
intersect
method returns true
and
Shape
entirely contains the rectangular area are
prohibitively expensive.
Shapes
this method might
return false
even though the Shape
contains
the rectangular area.
The Area
class performs
more accurate geometric computations than most
Shape
objects and therefore can be used if a more precise
answer is required.contains
in class Shape
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 areatrue
if the interior of the Shape
entirely contains the specified rectangular area;
false
otherwise or, if the Shape
contains the rectangular area and the
intersects
method returns true
and the containment calculations would be too expensive to
perform.Shape.intersects(float, float, float, float)
public PathIterator getPathIterator(BaseTransform tx)
CubicCurve2D
class does not
guarantee that modifications to the geometry of this
CubicCurve2D
object do not affect any iterations of
that geometry that are already in process.getPathIterator
in class Shape
tx
- an optional BaseTransform
to be applied to the
coordinates as they are returned in the iteration, or null
if untransformed coordinates are desiredPathIterator
object that returns the
geometry of the outline of this CubicCurve2D
, one
segment at a time.public PathIterator getPathIterator(BaseTransform tx, float flatness)
CubicCurve2D
class does not
guarantee that modifications to the geometry of this
CubicCurve2D
object do not affect any iterations of
that geometry that are already in process.getPathIterator
in class Shape
tx
- an optional BaseTransform
to be applied to the
coordinates as they are returned in the iteration, or null
if untransformed coordinates are desiredflatness
- 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 pointsPathIterator
object that returns the
geometry of the outline of this CubicCurve2D
,
one segment at a time.public CubicCurve2D copy()
Shape
Shape
instance.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
private float calcX(float t)
private float calcY(float t)