Package org.evoludo.geom
Class Path2D
Object
Path2D
Adapted from
java.awt.geom.Path2D
, merged with PathIterator
and stripped to the bare bones. In particular, all the Shape
stuff
and AffineTransform
removed. Generally made more GWT friendly.- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Adapted from java.awt.geom.PathIterator, merged with Path2D Iterator and CopyIterator. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) double[]
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) int
(package private) int
(package private) byte[]
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
static final int
An even-odd winding rule for determining the interior of a path.static final int
A non-zero winding rule for determining the interior of a path.(package private) int
-
Constructor Summary
ConstructorsConstructorDescriptionPath2D()
Constructs a new empty double precisionPath2D
object with a default winding rule ofWIND_NON_ZERO
.Path2D
(int rule) Constructs a new empty double precisionPath2D
object with the specified winding rule to control operations that require the interior of the path to be defined.Path2D
(int rule, int initialCapacity) Constructs a new empty double precisionPath2D
object with the specified winding rule and the specified initial capacity to store path segments.Path2D
(Path2D p2d, AffineTransform at) Constructs a new double precisionPath2D
object from an arbitraryPath2D
object, transformed by anAffineTransform
object. -
Method Summary
Modifier and TypeMethodDescription(package private) void
append
(double x, double y) Append the point with coordinates(x,y)
to this path.final void
append
(Path2D.Iterator pi, boolean connect) Appends the geometry of the specifiedPath2D.Iterator
object to the path, possibly connecting the new geometry to the existing path segments with a line segment.(package private) double[]
final void
Closes the current subpath by drawing a straight line back to the coordinates of the lastmoveTo
.static Path2D
createPolygon2D
(double[] x, double[] y) Construct a polygon from array ofx
- andy
coordinates.final void
curveTo
(double x1, double y1, double x2, double y2, double x3, double y3) Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates(x3,y3)
, using the specified points(x1,y1)
and(x2,y2)
as Bézier control points.(package private) static double[]
expandCoords
(double[] oldCoords, int needed) (package private) static byte[]
expandPointTypes
(byte[] oldPointTypes, int needed) final Rectangle2D
Returns a high precision and more accurate bounding box of thePath2D
than thegetBounds
method.final Point2D
Returns the coordinates most recently added to the end of the path as aPoint2D
object.final Path2D.Iterator
Returns an iterator object that iterates along this path.(package private) Point2D
getPoint
(int coordindex) Return the point in thePath2D
with the specified index.final int
Returns the fill style winding rule.boolean
isEmpty()
Check if the path is empty.final void
lineTo
(double x, double y) Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.final void
moveTo
(double x, double y) Adds a point to the path by moving to the specified coordinates specified in double precision.(package private) void
needRoom
(boolean needMove, int newCoords) final void
quadTo
(double x1, double y1, double x2, double y2) Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the specified coordinates(x2,y2)
, using the specified point(x1,y1)
as a quadratic parametric control point.final void
reset()
Resets the path to empty.final void
setWindingRule
(int rule) Sets the winding rule for this path to the specified value.toString()
final void
Transforms the geometry of this path using the specifiedAffineTransform
.void
translate
(double dx, double dy) Translate path.final void
Trim excessive storage ofPath2D
.
-
Field Details
-
WIND_EVEN_ODD
public static final int WIND_EVEN_ODDAn even-odd winding rule for determining the interior of a path.- Since:
- 1.6
- See Also:
-
WIND_NON_ZERO
public static final int WIND_NON_ZEROA non-zero winding rule for determining the interior of a path.- Since:
- 1.6
- See Also:
-
SEG_MOVETO
private static final byte SEG_MOVETO- See Also:
-
SEG_LINETO
private static final byte SEG_LINETO- See Also:
-
SEG_QUADTO
private static final byte SEG_QUADTO- See Also:
-
SEG_CUBICTO
private static final byte SEG_CUBICTO- See Also:
-
SEG_CLOSE
private static final byte SEG_CLOSE- See Also:
-
pointTypes
byte[] pointTypes -
numTypes
int numTypes -
numCoords
int numCoords -
windingRule
int windingRule -
INIT_SIZE
static final int INIT_SIZE- See Also:
-
EXPAND_MAX
static final int EXPAND_MAX- See Also:
-
EXPAND_MAX_COORDS
static final int EXPAND_MAX_COORDS- See Also:
-
EXPAND_MIN
static final int EXPAND_MIN- See Also:
-
doubleCoords
double[] doubleCoords
-
-
Constructor Details
-
Path2D
public Path2D()Constructs a new empty double precisionPath2D
object with a default winding rule ofWIND_NON_ZERO
.- Since:
- 1.6
-
Path2D
public Path2D(int rule) Constructs a new empty double precisionPath2D
object with the specified winding rule to control operations that require the interior of the path to be defined.- Parameters:
rule
- the winding rule- Since:
- 1.6
- See Also:
-
Path2D
public Path2D(int rule, int initialCapacity) Constructs a new empty double precisionPath2D
object with the specified winding rule and the specified initial capacity to store path segments. This number is an initial guess as to how many path segments are in the path, but the storage is expanded as needed to store whatever path segments are added to this path.- Parameters:
rule
- the winding ruleinitialCapacity
- the estimate for the number of path segments in the path- Since:
- 1.6
- See Also:
-
Path2D
Constructs a new double precisionPath2D
object from an arbitraryPath2D
object, transformed by anAffineTransform
object. All of the initial geometry and the winding rule for this path are taken from the specifiedPath2D
object and transformed by the specifiedAffineTransform
object.- Parameters:
p2d
- the specifiedPath2D
objectat
- the specifiedAffineTransform
object- Since:
- 1.6
-
-
Method Details
-
expandPointTypes
static byte[] expandPointTypes(byte[] oldPointTypes, int needed) -
trimToSize
public final void trimToSize()Trim excessive storage ofPath2D
. No data is lost. -
cloneCoordsDouble
-
append
void append(double x, double y) Append the point with coordinates(x,y)
to this path.- Parameters:
x
- thex
coordinate of the pointy
- they
coordinate of the point
-
getPoint
Return the point in thePath2D
with the specified index.- Parameters:
coordindex
- the index of the point- Returns:
- the point in the path
-
needRoom
void needRoom(boolean needMove, int newCoords) -
expandCoords
static double[] expandCoords(double[] oldCoords, int needed) -
moveTo
public final void moveTo(double x, double y) Adds a point to the path by moving to the specified coordinates specified in double precision.- Parameters:
x
- the specified X coordinatey
- the specified Y coordinate- Since:
- 1.6
-
lineTo
public final void lineTo(double x, double y) Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.- Parameters:
x
- the specified X coordinatey
- the specified Y coordinate- Since:
- 1.6
-
quadTo
public final void quadTo(double x1, double y1, double x2, double y2) Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the specified coordinates(x2,y2)
, using the specified point(x1,y1)
as a quadratic parametric control point. All coordinates are specified in double precision.- Parameters:
x1
- the X coordinate of the quadratic control pointy1
- the Y coordinate of the quadratic control pointx2
- the X coordinate of the final end pointy2
- the Y coordinate of the final end point- Since:
- 1.6
-
curveTo
public final void curveTo(double x1, double y1, double x2, double y2, double x3, double y3) Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates(x3,y3)
, using the specified points(x1,y1)
and(x2,y2)
as Bézier control points. All coordinates are specified in double precision.- Parameters:
x1
- the X coordinate of the first Bézier control pointy1
- the Y coordinate of the first Bézier control pointx2
- the X coordinate of the second Bézier control pointy2
- the Y coordinate of the second Bézier control pointx3
- the X coordinate of the final end pointy3
- the Y coordinate of the final end point- Since:
- 1.6
-
append
Appends the geometry of the specifiedPath2D.Iterator
object to the path, possibly connecting the new geometry to the existing path segments with a line segment. If theconnect
parameter istrue
and the path is not empty then any initialmoveTo
in the geometry of the appendedIterator
is turned into alineTo
segment. If the destination coordinates of such a connectinglineTo
segment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specifiedIterator
is ignored and the appended geometry is governed by the winding rule specified for this path.- Parameters:
pi
- theIterator
whose geometry is appended to this pathconnect
- a boolean to control whether or not to turn an initialmoveTo
segment into alineTo
segment to connect the new geometry to the existing path- Since:
- 1.6
-
transform
Transforms the geometry of this path using the specifiedAffineTransform
. The geometry is transformed in place, which permanently changes the boundary defined by this object.- Parameters:
at
- theAffineTransform
used to transform the area- Since:
- 1.6
-
translate
public void translate(double dx, double dy) Translate path.- Parameters:
dx
- shift path horizontally bydx
dy
- shift path vertically bydy
-
getBounds2D
Returns a high precision and more accurate bounding box of thePath2D
than thegetBounds
method. Note that there is no guarantee that the returnedRectangle2D
is the smallest bounding box that encloses thePath2D
, only that thePath2D
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.- Returns:
- an instance of
Rectangle2D
that is a high-precision bounding box of thePath2D
. - Since:
- 1.6
- Implementation Notes:
getBounds()
is not implemented
-
getPathIterator
Returns an iterator object that iterates along this path. boundary and provides access to a flattened view of thePath2D
outline geometry.Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.
Each call to this method returns a fresh
PathIterator
object that traverses the path independently from any otherPathIterator
objects in use at the same time.The iterator for this class is not multi-threaded safe, which means that the
Path2D
class does not guarantee that modifications to the geometry of thisPath2D
object do not affect any iterations of that geometry that are already in process.- Returns:
- a new
PathIterator
that iterates along the path - Since:
- 1.6
-
createPolygon2D
Construct a polygon from array ofx
- andy
coordinates. Essentially replaces java.awt.Polygon.- Parameters:
x
- array ofx
-coordinatesy
- array ofy
-coordinates- Returns:
- path of polygon
-
closePath
public final void closePath()Closes the current subpath by drawing a straight line back to the coordinates of the lastmoveTo
. If the path is already closed then this method has no effect.- Since:
- 1.6
-
getWindingRule
public final int getWindingRule()Returns the fill style winding rule.- Returns:
- an integer representing the current winding rule.
- Since:
- 1.6
- See Also:
-
setWindingRule
public final void setWindingRule(int rule) Sets the winding rule for this path to the specified value.- Parameters:
rule
- an integer representing the specified winding rule- Throws:
IllegalArgumentException
- ifrule
is not eitherWIND_EVEN_ODD
orWIND_NON_ZERO
- Since:
- 1.6
- See Also:
-
getCurrentPoint
Returns the coordinates most recently added to the end of the path as aPoint2D
object.- Returns:
- a
Point2D
object containing the ending coordinates of the path ornull
if there are no points in the path. - Since:
- 1.6
-
reset
public final void reset()Resets the path to empty. The append position is set back to the beginning of the path and all coordinates and point types are forgotten.- Since:
- 1.6
-
isEmpty
public boolean isEmpty()Check if the path is empty.- Returns:
true
if the path is empty
-
toString
-