org.eclipse.gef.geometry.planar

## Class Path

- java.lang.Object
- - org.eclipse.gef.geometry.planar.Path

All Implemented Interfaces:
  Serializable, Cloneable, IGeometry

    public class Path
    extends 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 within `PrecisionUtils`) to compensate for rounding effects.

See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`static class` `Path.Segment` Representation for different types of `Path.Segment`s.

### Field Summary

Fields
`static int` `WIND_EVEN_ODD` Winding rule for determining the interior of the `Path`.
`static int` `WIND_NON_ZERO` Winding rule for determining the interior of the `Path`.

### Constructor Summary

Constructors
Constructor and Description
`Path()` Creates a new empty path with a default winding rule of `WIND_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 rule `WIND_NON_ZERO`.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Path` `add(List<Path.Segment> segments)` Adds the given `List` of `Path.Segment`s to this `Path`.
`Path` `add(Path.Segment... segments)` Adds the given `Path.Segment`s to this `Path`.
`static Path` `add(Path pa, Path pb)` Unions the two specified `Path`s
`Object` `clone()` Overridden with public visibility as recommended within `Cloneable` .
`Path` `close()` Closes the current sub-path by drawing a straight line (line-to) to the location of the last move to.
`boolean` `contains(Point p)` Returns whether the given `Point` is contained within this `IGeometry`.
`boolean` `contains(Rectangle r)` Returns `true` if the given `Rectangle` is contained within `IGeometry`, `false` otherwise.
`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.
`boolean` `equals(Object obj)`
`static Path` `exclusiveOr(Path pa, Path pb)` Computes the area covered by the first or the second but not both given areas.
`Rectangle` `getBounds()` Returns the smallest `Rectangle` fully enclosing this `IGeometry`.
`Path` `getCopy()` Returns a new identical copy of this `IGeometry`.
`List<ICurve>` `getOutlines()` Returns a `List` of `ICurve`s, representing the outline of `this` `Path`.
`Path.Segment[]` `getSegments()` Returns the segments that make up this path.
`Path` `getTransformed(AffineTransform t)` Default implementation returning a transformed `Path` representation of this `IGeometry`.
`int` `getWindingRule()` Returns the winding rule used to determine the interior of this path.
`int` `hashCode()`
`static Path` `intersect(Path pa, Path pb)` Intersects the given areas.
`Path` `lineTo(double x, double y)` Adds a straight line segment from the current position to the specified end position.
`Path` `moveTo(double x, double y)` Changes the current position.
`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.
`Path` `reset()` Resets the path to be empty.
`Path` `setWindingRule(int windingRule)` Sets the winding rule of this `Path` to the passed-in integer constant which is either of: `WIND_NON_ZERO` (default) `WIND_EVEN_ODD`
`static Path` `subtract(Path pa, Path pb)` Subtracts the second given area from the first given area.
`Path` `toPath()` Converts this `IGeometry` into a `Path` representation.
`boolean` `touches(IGeometry g)` Returns `true` if the input `IGeometry` touches this `IGeometry`, i.e. there is at least one common point.
`boolean` `touches(Rectangle r)` Tests whether this `Path` and the given `Rectangle` touch, i.e. they have at least one `Point` in common.

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.eclipse.gef.geometry.planar.IGeometry

`touches`

### Field Detail

#### WIND_EVEN_ODD

    public static final int WIND_EVEN_ODD

Winding rule for determining the interior of the `Path`. Indicates that a `Point` is regarded to lie inside the `Path`, if any ray starting in that `Point` and pointing to infinity crosses the `Path.Segment`s of the `Path` an 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 the `Path`. Indicates that a `Point` is regarded to lie inside the `Path`, if any ray starting from that `Point` and pointing to infinity is crossed by `Path` `Path.Segment`s 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 of `WIND_NON_ZERO`.

#### Path

    public Path(int windingRule)

Creates a new empty path with given winding rule.

Parameters:
  `windingRule` - the winding rule to use; one of `WIND_EVEN_ODD` or `WIND_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 of `WIND_EVEN_ODD` or `WIND_NON_ZERO`
  `segments` - The segments to initialize the path with

#### Path

    public Path(Path.Segment... segments)

Creates a path from the given segments, using the default winding rule `WIND_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 specified `Path`s

Parameters:
  `pa` - the first area to add
  `pb` - 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 for
  `pb` - 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 intersect
  `pb` - 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 from
  `pb` - the area to subtract
Returns:
  the area covered by the first but not the second given area

#### add

    public final Path add(List<Path.Segment> segments)

Adds the given `List` of `Path.Segment`s to this `Path`.

Parameters:
  `segments` - The `Path.Segment`s to add to this `Path`.
Returns:
  `this` for convenience.

#### add

    public final Path add(Path.Segment... segments)

Adds the given `Path.Segment`s to this `Path`.

Parameters:
  `segments` - The `Path.Segment`s to add to this `Path`.
Returns:
  `this` for 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:
  `this` for convenience

#### contains

    public boolean contains(Point p)

Description copied from interface: `IGeometry`
Returns whether the given `Point` is contained within this `IGeometry`. This includes the case that the `Point` lies on the border of this `IGeometry`.

Specified by:
  `contains` in interface `IGeometry`
Parameters:
  `p` - The `Point` being tested for containment
Returns:
  `true` if the `Point` is contained within this `IGeometry`, `false` otherwise.

#### contains

    public boolean contains(Rectangle r)

Returns `true` if the given `Rectangle` is contained within `IGeometry`, `false` otherwise. TODO: Generalize to arbitrary `IGeometry` objects.

Parameters:
  `r` - The `Rectangle` to test
Returns:
  `true` if the `Rectangle` is fully contained within this `IGeometry`

#### 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 point
  `control1Y` - The y-coordinate of the first Bezier control point
  `control2X` - The x-coordinate of the second Bezier control point
  `control2Y` - The y-coordinate of the second Bezier control point
  `x` - The x-coordinate of the desired target point
  `y` - The y-coordinate of the desired target point
Returns:
  `this` for convenience

#### equals

    public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`

#### getBounds

    public Rectangle getBounds()

Description copied from interface: `IGeometry`
Returns the smallest `Rectangle` fully enclosing this `IGeometry`.

Specified by:
  `getBounds` in interface `IGeometry`
Returns:
  A new `Rectangle` object that fully encloses this `IGeometry`

#### getCopy

    public Path getCopy()

Description copied from interface: `IGeometry`
Returns a new identical copy of this `IGeometry`.

Specified by:
  `getCopy` in interface `IGeometry`
Returns:
  a copy identical to this `IGeometry`

#### getOutlines

    public List<ICurve> getOutlines()

Returns a `List` of `ICurve`s, representing the outline of `this` `Path`. For every `Path.Segment.LINE_TO`, `Path.Segment.QUAD_TO`, `Path.Segment.CUBIC_TO`, and `Path.Segment.CLOSE`, one `BezierCurve` is created that resembles that segment.

Returns:
  A `List` of `ICurve`s representing the outline of the given `Path`.

#### getSegments

    public Path.Segment[] getSegments()

Returns the segments that make up this path.

Returns:
  an array of `Path.Segment`s representing the segments of this path

#### getTransformed

    public Path getTransformed(AffineTransform t)

Default implementation returning a transformed `Path` representation of this `IGeometry`. Subclasses may override this method to return a more specific representation.

Specified by:
  `getTransformed` in interface `IGeometry`
Parameters:
  `t` - The `AffineTransform` to be applied
Returns:
  a transformed `Path` representation of this `IGeometry`

#### 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_ODD` or `WIND_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 point
  `y` - The y-coordinate of the desired target point
Returns:
  `this` for convenience

#### moveTo

    public final Path moveTo(double x,
                             double y)

Changes the current position. A new `Path.Segment` of type `Path.Segment.MOVE_TO` is added to this Path.

Parameters:
  `x` - The x-coordinate of the desired target point
  `y` - The y-coordinate of the desired target point
Returns:
  `this` for 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 point
  `controlY` - The y-coordinate of the control point
  `x` - The x-coordinate of the desired target point
  `y` - The y-coordinate of the desired target point
Returns:
  `this` for convenience

#### reset

    public final Path reset()

Resets the path to be empty.

Returns:
  `this` for convenience

#### setWindingRule

    public Path setWindingRule(int windingRule)

Sets the winding rule of this `Path` to the passed-in integer constant which is either of:

- `WIND_NON_ZERO` (default)
- `WIND_EVEN_ODD`

Parameters:
  `windingRule` - the new winding rule of this `Path`
Returns:
  `this` for convenience

#### toPath

    public Path toPath()

Description copied from interface: `IGeometry`
Converts this `IGeometry` into a `Path` representation.

Specified by:
  `toPath` in interface `IGeometry`
Returns:
  A new `Path` representation for this `IGeometry`.
See Also:
  `IGeometry.toPath()`

#### touches

    public boolean touches(Rectangle r)

Tests whether this `Path` and the given `Rectangle` touch, i.e. they have at least one `Point` in common.

Parameters:
  `r` - the `Rectangle` to test for at least one `Point` in common with this `Path`
Returns:
  `true` if this `Path` and the `Rectangle` touch, otherwise `false`
See Also:
  `IGeometry.touches(IGeometry)`

#### clone

    public Object clone()

Overridden with public visibility as recommended within `Cloneable` .

Overrides:
  `clone` in class `Object`

#### hashCode

    public final int hashCode()

Overrides:
  `hashCode` in class `Object`
See Also:
  `Object.hashCode()`

#### touches

    public boolean touches(IGeometry g)

Description copied from interface: `IGeometry`
Returns `true` if the input `IGeometry` touches this `IGeometry`, i.e. there is at least one common point.

Specified by:
  `touches` in interface `IGeometry`
Parameters:
  `g` - The `IGeometry` for the intersection test
Returns:
  `true` if the input `IGeometry` and this `IGeometry` have at least one common point.