math.geom2d.curve
Class GeneralPath2D
- java.lang.Object
-
- math.geom2d.curve.GeneralPath2D
-
- All Implemented Interfaces:
- java.awt.Shape, java.lang.Cloneable
public final class GeneralPath2D extends java.lang.Object implements java.awt.Shape, java.lang.CloneableTheGeneralPathclass represents a geometric path constructed from straight lines, and quadratic and cubic (Bezier) curves. It can contain multiple subpaths.The winding rule specifies how the interior of a path is determined. There are two types of winding rules: EVEN_ODD and NON_ZERO.
An EVEN_ODD winding rule means that enclosed regions of the path alternate between interior and exterior areas as traversed from the outside of the path towards a point inside the region.
A NON_ZERO winding rule means that if a ray is drawn in any direction from a given point to infinity and the places where the path intersects the ray are examined, the point is inside of the path if and only if the number of times that the path crosses the ray from left to right does not equal the number of times that the path crosses the ray from right to left.
-
-
Field Summary
Fields Modifier and Type Field and Description static intWIND_EVEN_ODDAn even-odd winding rule for determining the interior of a path.static intWIND_NON_ZEROA non-zero winding rule for determining the interior of a path.
-
Constructor Summary
Constructors Constructor and Description GeneralPath2D()Constructs a newGeneralPathobject.GeneralPath2D(int rule)Constructs a newGeneralPathobject with the specified winding rule to control operations that require the interior of the path to be defined.GeneralPath2D(int rule, int initialCapacity)Constructs a newGeneralPathobject with the specified winding rule and the specified initial capacity to store path coordinates.GeneralPath2D(java.awt.Shape s)Constructs a newGeneralPathobject from an arbitraryShapeobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidappend(java.awt.geom.PathIterator pi, boolean connect)Appends the geometry of the specifiedPathIteratorobject to the path, possibly connecting the new geometry to the existing path segments with a line segment.voidappend(java.awt.Shape s, boolean connect)Appends the geometry of the specifiedShapeobject to the path, possibly connecting the new geometry to the existing path segments with a line segment.java.lang.Objectclone()Deprecated.use copy constructor instead (0.11.2)voidclosePath()Closes the current subpath by drawing a straight line back to the coordinates of the lastmoveTo.booleancontains(double x, double y)Tests if the specified coordinates are inside the boundary of thisShape.booleancontains(double x, double y, double w, double h)Tests if the specified rectangular area is inside the boundary of thisShape.booleancontains(java.awt.geom.Point2D p)Tests if the specifiedPoint2Dis inside the boundary of thisShape.booleancontains(Point2D p)Tests if the specifiedPoint2Dis inside the boundary of thisShape.booleancontains(java.awt.geom.Rectangle2D r)Tests if the specifiedRectangle2Dis inside the boundary of thisShape.java.awt.ShapecreateTransformedShape(java.awt.geom.AffineTransform at)Returns a new transformedShape.voidcurveTo(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 Bezier curve that intersects both the current coordinates and the coordinates (x3, y3), using the specified points (x1, y1) and (x2, y2) as Bezier control points.voidcurveTo(Point2D p1, Point2D p2, Point2D p3)Adds a curved segment, defined by three new points, to the path by drawing a Bezier curve that intersects both the current coordinates and the coordinates (x3, y3), using the specified points (x1, y1) and (x2, y2) as Bezier control points.booleanequals(java.lang.Object obj)java.awt.RectanglegetBounds()Return the bounding box of the path.java.awt.geom.Rectangle2DgetBounds2D()Returns the bounding box of the path.Point2DgetCurrentPoint()Returns the coordinates most recently added to the end of the path as aPoint2Dobject.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at)Returns aPathIteratorobject that iterates along the boundary of thisShapeand provides access to the geometry of the outline of thisShape.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)Returns aPathIteratorobject that iterates along the boundary of the flattenedShapeand provides access to the geometry of the outline of theShape.intgetWindingRule()Returns the fill style winding rule.booleanintersects(double x, double y, double w, double h)Tests if the interior of thisShapeintersects the interior of a specified set of rectangular coordinates.booleanintersects(java.awt.geom.Rectangle2D r)Tests if the interior of thisShapeintersects the interior of a specifiedRectangle2D.voidlineTo(double x, double y)Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates.voidlineTo(Point2D p)Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates.voidmoveTo(double x, double y)Adds a point to the path by moving to the specified coordinates.voidmoveTo(Point2D p)Adds a point to the path by moving to the specified coordinates.voidquadTo(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 coordinates (x2, y2), using the specified point (x1, y1) as a quadratic parametric control point.voidquadTo(Point2D p1, Point2D p2)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 coordinates (x2, y2), using the specified point (x1, y1) as a quadratic parametric control point.voidreset()Resets the path to empty.voidsetWindingRule(int rule)Sets the winding rule for this path to the specified value.voidtransform(java.awt.geom.AffineTransform at)Transforms the geometry of this path using the specifiedAffineTransform.
-
-
-
Field Detail
-
WIND_EVEN_ODD
public static final int WIND_EVEN_ODD
An even-odd winding rule for determining the interior of a path.- See Also:
- Constant Field Values
-
WIND_NON_ZERO
public static final int WIND_NON_ZERO
A non-zero winding rule for determining the interior of a path.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GeneralPath2D
public GeneralPath2D()
Constructs a newGeneralPathobject. If an operation performed on this path requires the interior of the path to be defined then the default NON_ZERO winding rule is used.- See Also:
WIND_NON_ZERO
-
GeneralPath2D
public GeneralPath2D(int rule)
Constructs a newGeneralPathobject with the specified winding rule to control operations that require the interior of the path to be defined.- Parameters:
rule- the winding rule- See Also:
WIND_EVEN_ODD,WIND_NON_ZERO
-
GeneralPath2D
public GeneralPath2D(int rule, int initialCapacity)Constructs a newGeneralPathobject with the specified winding rule and the specified initial capacity to store path coordinates. 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- See Also:
WIND_EVEN_ODD,WIND_NON_ZERO
-
GeneralPath2D
public GeneralPath2D(java.awt.Shape s)
Constructs a newGeneralPathobject from an arbitraryShapeobject. All of the initial geometry and the winding rule for this path are taken from the specifiedShapeobject.- Parameters:
s- the specifiedShapeobject
-
-
Method Detail
-
moveTo
public void moveTo(double x, double y)Adds a point to the path by moving to the specified coordinates.- Parameters:
x- the x-coordinate of the destinationy- the y-coordinate of the destination
-
moveTo
public void moveTo(Point2D p)
Adds a point to the path by moving to the specified coordinates.- Parameters:
p- the specified point
-
lineTo
public 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.- Parameters:
x- the x-coordinate of the destinationy- the y-coordinate of the destination
-
lineTo
public void lineTo(Point2D p)
Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates.- Parameters:
p- the coordinate of the destionation point
-
quadTo
public 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 coordinates (x2, y2), using the specified point (x1, y1) as a quadratic parametric control point.- Parameters:
x1- the x-coordinate of the control pointy1- the y-coordinate of the control pointx2- the x-coordinate of the end pointy2- the y-coordinate of the end point
-
quadTo
public void quadTo(Point2D p1, Point2D p2)
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 coordinates (x2, y2), using the specified point (x1, y1) as a quadratic parametric control point.- Parameters:
p1- the control pointp2- the end point
-
curveTo
public 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 Bezier curve that intersects both the current coordinates and the coordinates (x3, y3), using the specified points (x1, y1) and (x2, y2) as Bezier control points.- Parameters:
x1- the x-coordinate of the first control pointy1- the y-coordinate of the first control pointx2- the x-coordinate of the second control pointy2- the y-coordinate of the second control pointx3- the x-coordinate of the end pointy3- the y-coordinate of the end point
-
curveTo
public void curveTo(Point2D p1, Point2D p2, Point2D p3)
Adds a curved segment, defined by three new points, to the path by drawing a Bezier curve that intersects both the current coordinates and the coordinates (x3, y3), using the specified points (x1, y1) and (x2, y2) as Bezier control points.- Parameters:
p1- the coordinates of the first control pointp2- the coordinates of the second control pointp3- the coordinates of the final endpoint
-
closePath
public 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.
-
append
public void append(java.awt.Shape s, boolean connect)Appends the geometry of the specifiedShapeobject to the path, possibly connecting the new geometry to the existing path segments with a line segment. If theconnectparameter istrueand the path is not empty then any initialmoveToin the geometry of the appendedShapeis turned into alineTosegment. If the destination coordinates of such a connectinglineTosegment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specifiedShapeis ignored and the appended geometry is governed by the winding rule specified for this path.- Parameters:
s- theShapewhose geometry is appended to this pathconnect- a boolean to control whether or not to turn an initialmoveTosegment into alineTosegment to connect the new geometry to the existing path
-
append
public void append(java.awt.geom.PathIterator pi, boolean connect)Appends the geometry of the specifiedPathIteratorobject to the path, possibly connecting the new geometry to the existing path segments with a line segment. If theconnectparameter istrueand the path is not empty then any initialmoveToin the geometry of the appendedShapeis turned into alineTosegment. If the destination coordinates of such a connectinglineTosegment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specifiedShapeis ignored and the appended geometry is governed by the winding rule specified for this path.- Parameters:
pi- thePathIteratorwhose geometry is appended to this pathconnect- a boolean to control whether or not to turn an initialmoveTosegment into alineTosegment to connect the new geometry to the existing path
-
getWindingRule
public int getWindingRule()
Returns the fill style winding rule.- Returns:
- an integer representing the current winding rule.
- See Also:
WIND_EVEN_ODD,WIND_NON_ZERO
-
setWindingRule
public 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:
- ifIllegalArgumentExceptionruleis not eitherWIND_EVEN_ODDorWIND_NON_ZERO- See Also:
WIND_EVEN_ODD,WIND_NON_ZERO
-
getCurrentPoint
public Point2D getCurrentPoint()
Returns the coordinates most recently added to the end of the path as aPoint2Dobject.- Returns:
- a
Point2Dobject containing the ending coordinates of the path ornullif there are no points in the path.
-
reset
public 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.
-
transform
public void transform(java.awt.geom.AffineTransform at)
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- theAffineTransformused to transform the area
-
createTransformedShape
public java.awt.Shape createTransformedShape(java.awt.geom.AffineTransform at)
Returns a new transformedShape.- Parameters:
at- theAffineTransformused to transform a newShape.- Returns:
- a new
Shape, transformed with the specifiedAffineTransform.
-
getBounds
public java.awt.Rectangle getBounds()
Return the bounding box of the path.- Specified by:
getBoundsin interfacejava.awt.Shape- Returns:
- a
Rectangleobject that bounds the current path.
-
getBounds2D
public java.awt.geom.Rectangle2D getBounds2D()
Returns the bounding box of the path.- Specified by:
getBounds2Din interfacejava.awt.Shape- Returns:
- a
Rectangle2Dobject that bounds the current path.
-
contains
public boolean contains(double x, double y)Tests if the specified coordinates are inside the boundary of thisShape.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
x- the x-coordinate of the pointy- the y-coordinate of the point- Returns:
trueif the specified coordinates are inside thisShape;falseotherwise
-
contains
public boolean contains(java.awt.geom.Point2D p)
Tests if the specifiedPoint2Dis inside the boundary of thisShape.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
p- the specifiedPoint2D- Returns:
trueif thisShapecontains the specifiedPoint2D,falseotherwise.
-
contains
public boolean contains(Point2D p)
Tests if the specifiedPoint2Dis inside the boundary of thisShape.- Parameters:
p- the specifiedPoint2D- Returns:
trueif thisShapecontains the specifiedPoint2D,falseotherwise.
-
contains
public boolean contains(double x, double y, double w, double h)Tests if the specified rectangular area is inside the boundary of thisShape.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
x- the x coordinate of the rectangley- the y coordinate of the rectanglew- the width of the specified rectangular areah- the height of the specified rectangular area- Returns:
trueif thisShapecontains the specified rectangluar area;falseotherwise.
-
contains
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the specifiedRectangle2Dis inside the boundary of thisShape.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
r- a specifiedRectangle2D- Returns:
trueif thisShapebounds the specifiedRectangle2D;falseotherwise.
-
intersects
public boolean intersects(double x, double y, double w, double h)Tests if the interior of thisShapeintersects the interior of a specified set of rectangular coordinates.- Specified by:
intersectsin interfacejava.awt.Shape- Parameters:
x- the position of the left cornery- the position of the bottom cornerw- the width of the specified rectangular coordinatesh- the height of the specified rectangular coordinates- Returns:
trueif thisShapeand the interior of the specified set of rectangular coordinates intersect each other;falseotherwise.
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if the interior of thisShapeintersects the interior of a specifiedRectangle2D.- Specified by:
intersectsin interfacejava.awt.Shape- Parameters:
r- the specifiedRectangle2D- Returns:
trueif thisShapeand the interior of the specifiedRectangle2Dintersect each other;falseotherwise.
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Returns aPathIteratorobject that iterates along the boundary of thisShapeand provides access to the geometry of the outline of thisShape. The iterator for this class is not multi-threaded safe, which means that thisGeneralPathclass does not guarantee that modifications to the geometry of thisGeneralPathobject do not affect any iterations of that geometry that are already in process.- Specified by:
getPathIteratorin interfacejava.awt.Shape- Parameters:
at- anAffineTransform- Returns:
- a new
PathIteratorthat iterates along the boundary of thisShapeand provides access to the geometry of thisShape's outline
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)Returns aPathIteratorobject that iterates along the boundary of the flattenedShapeand provides access to the geometry of the outline of theShape. The iterator for this class is not multi-threaded safe, which means that thisGeneralPathclass does not guarantee that modifications to the geometry of thisGeneralPathobject do not affect any iterations of that geometry that are already in process.- Specified by:
getPathIteratorin interfacejava.awt.Shape- Parameters:
at- anAffineTransformflatness- the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve- Returns:
- a new
PathIteratorthat iterates along the flattenedShapeboundary.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
clone
@Deprecated public java.lang.Object clone()
Deprecated. use copy constructor instead (0.11.2)- Overrides:
clonein classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG