Package org.eclipse.gef.geometry.planar
Class Path
- java.lang.Object
-
- org.eclipse.gef.geometry.planar.Path
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,IGeometry
public class Path extends java.lang.Object implements IGeometry
Represents the geometric shape of a path, which may consist of independent subgraphs. Note that while all manipulations (e.g. within shrink, expand) within this class are based on double precision, all comparisons (e.g. within contains, intersects, equals, etc.) are based on a limited precision (with an accuracy defined withinPrecisionUtils) to compensate for rounding effects.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPath.SegmentRepresentation for different types ofPath.Segments.
-
Field Summary
Fields Modifier and Type Field Description static intWIND_EVEN_ODDWinding rule for determining the interior of thePath.static intWIND_NON_ZEROWinding rule for determining the interior of thePath.
-
Constructor Summary
Constructors Constructor Description Path()Creates a new empty path with a default winding rule ofWIND_NON_ZERO.Path(int windingRule)Creates a new empty path with given winding rule.Path(int windingRule, Path.Segment... segments)Creates a path from the given segments, using the given winding rule.Path(Path.Segment... segments)Creates a path from the given segments, using the default winding ruleWIND_NON_ZERO.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pathadd(java.util.List<Path.Segment> segments)Pathadd(Path.Segment... segments)Adds the givenPath.Segments to thisPath.static Pathadd(Path pa, Path pb)Unions the two specifiedPathsjava.lang.Objectclone()Overridden with public visibility as recommended withinCloneable.Pathclose()Closes the current sub-path by drawing a straight line (line-to) to the location of the last move to.booleancontains(Point p)booleancontains(Rectangle r)PathcubicTo(double control1X, double control1Y, double control2X, double control2Y, double x, double y)Adds a cubic Bezier curve segment from the current position to the specified end position, using the two provided control points as Bezier control points.booleanequals(java.lang.Object obj)static PathexclusiveOr(Path pa, Path pb)Computes the area covered by the first or the second but not both given areas.RectanglegetBounds()PathgetCopy()Returns a new identical copy of thisIGeometry.java.util.List<ICurve>getOutlines()Path.Segment[]getSegments()Returns the segments that make up this path.PathgetTransformed(AffineTransform t)intgetWindingRule()Returns the winding rule used to determine the interior of this path.inthashCode()static Pathintersect(Path pa, Path pb)Intersects the given areas.PathlineTo(double x, double y)Adds a straight line segment from the current position to the specified end position.PathmoveTo(double x, double y)Changes the current position.PathquadTo(double controlX, double controlY, double x, double y)Adds a quadratic curve segment from the current position to the specified end position, using the provided control point as a parametric control point.Pathreset()Resets the path to be empty.PathsetWindingRule(int windingRule)Sets the winding rule of thisPathto the passed-in integer constant which is either of:WIND_NON_ZERO(default)WIND_EVEN_ODDstatic Pathsubtract(Path pa, Path pb)Subtracts the second given area from the first given area.PathtoPath()booleantouches(IGeometry g)booleantouches(Rectangle r)
-
-
-
Field Detail
-
WIND_EVEN_ODD
public static final int WIND_EVEN_ODD
Winding rule for determining the interior of thePath. Indicates that aPointis regarded to lie inside thePath, if any ray starting in thatPointand pointing to infinity crosses thePath.Segments of thePathan odd number of times.- See Also:
- Constant Field Values
-
WIND_NON_ZERO
public static final int WIND_NON_ZERO
Winding rule for determining the interior of thePath. Indicates that aPointis regarded to lie inside thePath, if any ray starting from thatPointand pointing to infinity is crossed byPathPath.Segments a different number of times in the counter-clockwise direction than in the clockwise direction.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Path
public Path()
Creates a new empty path with a default winding rule ofWIND_NON_ZERO.
-
Path
public Path(int windingRule)
Creates a new empty path with given winding rule.- Parameters:
windingRule- the winding rule to use; one ofWIND_EVEN_ODDorWIND_NON_ZERO
-
Path
public Path(int windingRule, Path.Segment... segments)Creates a path from the given segments, using the given winding rule.- Parameters:
windingRule- the winding rule to use; one ofWIND_EVEN_ODDorWIND_NON_ZEROsegments- The segments to initialize the path with
-
Path
public Path(Path.Segment... segments)
Creates a path from the given segments, using the default winding ruleWIND_NON_ZERO.- Parameters:
segments- The segments to initialize the path with
-
-
Method Detail
-
add
public static Path add(Path pa, Path pb)
Unions the two specifiedPaths- Parameters:
pa- the first area to addpb- the second area to add- Returns:
- the sum of the areas
-
exclusiveOr
public static Path exclusiveOr(Path pa, Path pb)
Computes the area covered by the first or the second but not both given areas.- Parameters:
pa- the first area to compute the xor forpb- the second area to compute the xor for- Returns:
- the exclusive-or of the areas
-
intersect
public static Path intersect(Path pa, Path pb)
Intersects the given areas.- Parameters:
pa- the first area to intersectpb- the second area to intersect- Returns:
- the intersection of the areas, i.e. the area covered by both areas
-
subtract
public static Path subtract(Path pa, Path pb)
Subtracts the second given area from the first given area.- Parameters:
pa- the area to subtract frompb- the area to subtract- Returns:
- the area covered by the first but not the second given area
-
add
public final Path add(java.util.List<Path.Segment> segments)
- Parameters:
segments- ThePath.Segments to add to thisPath.- Returns:
thisfor convenience.
-
add
public final Path add(Path.Segment... segments)
Adds the givenPath.Segments to thisPath.- Parameters:
segments- ThePath.Segments to add to thisPath.- Returns:
thisfor convenience.
-
close
public final Path close()
Closes the current sub-path by drawing a straight line (line-to) to the location of the last move to.- Returns:
thisfor convenience
-
contains
public boolean contains(Rectangle r)
-
cubicTo
public final Path cubicTo(double control1X, double control1Y, double control2X, double control2Y, double x, double y)
Adds a cubic Bezier curve segment from the current position to the specified end position, using the two provided control points as Bezier control points.- Parameters:
control1X- The x-coordinate of the first Bezier control pointcontrol1Y- The y-coordinate of the first Bezier control pointcontrol2X- The x-coordinate of the second Bezier control pointcontrol2Y- The y-coordinate of the second Bezier control pointx- The x-coordinate of the desired target pointy- The y-coordinate of the desired target point- Returns:
thisfor convenience
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getCopy
public Path getCopy()
Description copied from interface:IGeometryReturns a new identical copy of thisIGeometry.
-
getOutlines
public java.util.List<ICurve> getOutlines()
Returns aListofICurves, representing the outline ofthisPath. For everyPath.Segment.LINE_TO,Path.Segment.QUAD_TO,Path.Segment.CUBIC_TO, andPath.Segment.CLOSE, oneBezierCurveis created that resembles that segment.
-
getSegments
public Path.Segment[] getSegments()
Returns the segments that make up this path.- Returns:
- an array of
Path.Segments representing the segments of this path
-
getTransformed
public Path getTransformed(AffineTransform t)
Default implementation returning a transformedPathrepresentation of thisIGeometry. Subclasses may override this method to return a more specific representation.- Specified by:
getTransformedin interfaceIGeometry- Parameters:
t- TheAffineTransformto be applied- Returns:
- a transformed
Pathrepresentation of thisIGeometry
-
getWindingRule
public int getWindingRule()
Returns the winding rule used to determine the interior of this path.- Returns:
- the winding rule, i.e. one of
WIND_EVEN_ODDorWIND_NON_ZERO
-
lineTo
public final Path lineTo(double x, double y)
Adds a straight line segment from the current position to the specified end position.- Parameters:
x- The x-coordinate of the desired target pointy- The y-coordinate of the desired target point- Returns:
thisfor convenience
-
moveTo
public final Path moveTo(double x, double y)
Changes the current position. A newPath.Segmentof typePath.Segment.MOVE_TOis added to this Path.- Parameters:
x- The x-coordinate of the desired target pointy- The y-coordinate of the desired target point- Returns:
thisfor convenience
-
quadTo
public final Path quadTo(double controlX, double controlY, double x, double y)
Adds a quadratic curve segment from the current position to the specified end position, using the provided control point as a parametric control point.- Parameters:
controlX- The x-coordinate of the control pointcontrolY- The y-coordinate of the control pointx- The x-coordinate of the desired target pointy- The y-coordinate of the desired target point- Returns:
thisfor convenience
-
reset
public final Path reset()
Resets the path to be empty.- Returns:
thisfor convenience
-
setWindingRule
public Path setWindingRule(int windingRule)
Sets the winding rule of thisPathto the passed-in integer constant which is either of:WIND_NON_ZERO(default)WIND_EVEN_ODD
- Parameters:
windingRule- the new winding rule of thisPath- Returns:
thisfor convenience
-
toPath
public Path toPath()
Description copied from interface:IGeometry- Specified by:
toPathin interfaceIGeometry- Returns:
- A new
Pathrepresentation for thisIGeometry. - See Also:
IGeometry.toPath()
-
touches
public boolean touches(Rectangle r)
-
clone
public java.lang.Object clone()
Overridden with public visibility as recommended withinCloneable.- Overrides:
clonein classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
-