Package org.eclipse.gef.geometry.planar

## Class Line

- java.lang.Object
- - org.eclipse.gef.geometry.planar.BezierCurve
  - - org.eclipse.gef.geometry.planar.Line

All Implemented Interfaces:
  `java.io.Serializable`, `java.lang.Cloneable`, `ICurve`, `IGeometry`, `IRotatable<BezierCurve>`, `IScalable<BezierCurve>`, `ITranslatable<BezierCurve>`

    public class Line
    extends BezierCurve

Represents the geometric shape of a line (or linear curve). 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

### Constructor Summary

Constructors
`Line​(double... coordinates)` Constructs a new `Line` from the given coordinate values.
`Line​(double x1, double y1, double x2, double y2)` Constructs a new `Line`, which connects the two `Point`s given indirectly by their coordinates
`Line​(Point... points)` Constructs a new `Line`, which connects the two `Point`s given.
`Line​(Point p1, Point p2)` Constructs a new `Line` which connects the two given `Point`s

### Method Summary

All Methods Instance Methods Concrete Methods
`java.lang.Object` `clone()` Overridden with public visibility as recommended within `Cloneable` .
`boolean` `contains​(Point p)` Returns whether the given `Point` is contained within this `IGeometry`.
`boolean` `equals​(double x1, double y1, double x2, double y2)` Tests whether this `Line` is equal to the line given implicitly by the given point coordinates.
`Point` `get​(double t)` Computes the `Point` on this `BezierCurve` at parameter value t, which is expected to lie in the parameter `BezierCurve.Interval` `[0;1]`.
`Rectangle` `getBounds()` Returns the smallest `Rectangle` containing this `Line`'s start and end point
`Line` `getCopy()` Returns a new `Line`, which has the same start and end point coordinates as this one.
`Angle` `getDirectionCCW()` Returns the counter-clockwise angle between the x axis and this `Line`.
`Angle` `getDirectionCW()` Returns the clockwise angle between the x axis and this `Line`.
`Point` `getIntersection​(Line l)` Returns the single intersection point between this `Line` and the given one, in case it exists.
`Point[]` `getIntersections​(BezierCurve curve)` Returns the `Point`s of intersection of this and the given other `BezierCurve`.
`double` `getLength()` Calculates the distance between the `start` and the `end point` of this `Line`.
`Point[]` `getPoints()` Returns an array, which contains two `Point`s representing the start and end points of this `Line`
`Point` `getProjection​(Point p)` Returns a projection of the given reference `Point` onto this `ICurve`, i.e. a `Point` on this `ICurve` that is closest to the given reference `Point`.
`Line` `getTransformed​(AffineTransform t)` Default implementation returning a transformed `Path` representation of this `IGeometry`.
`int` `hashCode()`
`boolean` `intersects​(ICurve c)` Tests if this `ICurve` and the given `ICurve` intersect, i.e.
`boolean` `intersects​(Line l)` Provides an optimized version of the `BezierCurve.intersects(ICurve)` method.
`boolean` `overlaps​(BezierCurve c)` Checks if this `BezierCurve` and the given other `BezierCurve` overlap, i.e. an infinite set of intersection `Point`s exists.
`boolean` `overlaps​(Line l)` Tests whether this `Line` and the given other `Line` overlap, i.e. they share an infinite number of `Point`s.
`Line` `setLine​(double x1, double y1, double x2, double y2)` Initializes this `Line` with the given start and end point coordinates
`Line` `setLine​(Line l)` Initializes this `Line` with the start and end point coordinates of the given one.
`Line` `setLine​(Point p1, Point p2)` Initializes this `Line` with the start and end point coordinates provided by the given points
`Line` `setX1​(double x1)` Sets the x-coordinate of the start `Point` of this `Line` to the given value.
`Line` `setX2​(double x2)` Sets the x-coordinate of the end `Point` of this `Line` to the given value.
`Line` `setY1​(double y1)` Sets the y-coordinate of the start `Point` of this `Line` to the given value.
`Line` `setY2​(double y2)` Sets the y-coordinate of the end `Point` of this `Line` to the given value.
`Path` `toPath()` Returns a `Path` approximating this `BezierCurve` using `Line` segments.
`java.lang.String` `toString()`
`boolean` `touches​(IGeometry g)` Returns `true` if the input `IGeometry` touches this `IGeometry`, i.e. there is at least one common point.
`boolean` `touches​(Line l)` Tests whether this `Line` and the given one share at least one common point.

### Methods inherited from class org.eclipse.gef.geometry.planar.BezierCurve

`contains, equals, getClipped, getControlBounds, getDerivative, getElevated, getIntersections, getOffset, getOverlap, getOverlaps, getP1, getP2, getParameterAt, getPoint, getRotatedCCW, getRotatedCCW, getRotatedCCW, getRotatedCW, getRotatedCW, getRotatedCW, getScaled, getScaled, getScaled, getScaled, getScaled, getScaled, getTranslated, getTranslated, getX1, getX2, getY1, getY2, overlaps, rotateCCW, rotateCCW, rotateCCW, rotateCW, rotateCW, rotateCW, scale, scale, scale, scale, scale, scale, setP1, setP2, setPoint, split, toBezier, toCubic, toLine, toLineStrip, toLineStrip, toPoints, toQuadratic, translate, translate`

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

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

### Constructor Detail

#### Line

    public Line​(double... coordinates)

Constructs a new `Line` from the given coordinate values.

Parameters:
  `coordinates` - A varargs of 4 doubles, providing the x and y coordinates of the start point, followed by those of the end point
See Also:
  `BezierCurve(double[])`

#### Line

    public Line​(double x1,
                double y1,
                double x2,
                double y2)

Constructs a new `Line`, which connects the two `Point`s given indirectly by their coordinates

Parameters:
  `x1` - the x-coordinate of the start point
  `y1` - the y-coordinate of the start point
  `x2` - the x-coordinate of the end point
  `y2` - the y-coordinate of the end point

#### Line

    public Line​(Point... points)

Constructs a new `Line`, which connects the two `Point`s given.

Parameters:
  `points` - A varargs of two points serving as the start and end point of this line

#### Line

    public Line​(Point p1,
                Point p2)

Constructs a new `Line` which connects the two given `Point`s

Parameters:
  `p1` - the start point
  `p2` - the end point

### Method Detail

#### 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`
Overrides:
  `contains` in class `BezierCurve`
Parameters:
  `p` - The `Point` being tested for containment
Returns:
  `true` if the `Point` is contained within this `IGeometry`, `false` otherwise.

#### equals

    public boolean equals​(double x1,
                          double y1,
                          double x2,
                          double y2)

Tests whether this `Line` is equal to the line given implicitly by the given point coordinates.

Parameters:
  `x1` - the x-coordinate of the start point of the line to test
  `y1` - the y-coordinate of the start point of the line to test
  `x2` - the x-coordinate of the end point of the line to test
  `y2` - the y-coordinate of the end point of the line to test
Returns:
  `true` if the given start and end point coordinates are (imprecisely) equal to this `Line` 's start and end point coordinates

#### get

    public Point get​(double t)

Description copied from class: `BezierCurve`
Computes the `Point` on this `BezierCurve` at parameter value t, which is expected to lie in the parameter `BezierCurve.Interval` `[0;1]`.

Overrides:
  `get` in class `BezierCurve`
Parameters:
  `t` - the parameter value for which this `BezierCurve` is evaluated
Returns:
  the `Point` on this `BezierCurve` at the given parameter value

#### getBounds

    public Rectangle getBounds()

Returns the smallest `Rectangle` containing this `Line`'s start and end point

Specified by:
  `getBounds` in interface `IGeometry`
Overrides:
  `getBounds` in class `BezierCurve`
Returns:
  A new `Rectangle` object that fully encloses this `IGeometry`
See Also:
  `IGeometry.getBounds()`

#### getCopy

    public Line getCopy()

Returns a new `Line`, which has the same start and end point coordinates as this one.

Specified by:
  `getCopy` in interface `IGeometry`
Overrides:
  `getCopy` in class `BezierCurve`
Returns:
  a new `Line` with the same start and end point coordinates

#### getDirectionCCW

    public Angle getDirectionCCW()

Returns the counter-clockwise angle between the x axis and this `Line`.

Returns:
  Returns the counter-clockwise angle between the x axis and this `Line`.

#### getDirectionCW

    public Angle getDirectionCW()

Returns the clockwise angle between the x axis and this `Line`.

Returns:
  Returns the clockwise angle between the x axis and this `Line`.

#### getIntersection

    public Point getIntersection​(Line l)

Returns the single intersection point between this `Line` and the given one, in case it exists. Note that even in case `intersects(org.eclipse.gef.geometry.planar.ICurve)` returns true, there may not be a single intersection point in case both lines overlap in more than one point.

Parameters:
  `l` - the Line, for which to compute the intersection point
Returns:
  the single intersection point between this `Line` and the given one, in case it intersects, `null` instead

#### getIntersections

    public Point[] getIntersections​(BezierCurve curve)

Description copied from class: `BezierCurve`
Returns the `Point`s of intersection of this and the given other `BezierCurve`.

Overrides:
  `getIntersections` in class `BezierCurve`
Parameters:
  `curve` - the `BezierCurve` which is searched for `Point`s of intersection with this `BezierCurve`
Returns:
  the `Point`s of intersection of this `BezierCurve` and the given other `BezierCurve`

#### getLength

    public double getLength()

Calculates the distance between the `start` and the `end point` of this `Line`.

Returns:
  The distance between start and end points.
See Also:
  `Point.getDistance(Point)`

#### getPoints

    public Point[] getPoints()

Returns an array, which contains two `Point`s representing the start and end points of this `Line`

Overrides:
  `getPoints` in class `BezierCurve`
Returns:
  an array with two `Point`s, whose x and y coordinates match those of this `Line`'s start and end point

#### getProjection

    public Point getProjection​(Point p)

Description copied from interface: `ICurve`
Returns a projection of the given reference `Point` onto this `ICurve`, i.e. a `Point` on this `ICurve` that is closest to the given reference `Point`. Note, that

Specified by:
  `getProjection` in interface `ICurve`
Overrides:
  `getProjection` in class `BezierCurve`
Parameters:
  `p` - The reference `Point` for which to return the projection.
Returns:
  The projection of the given reference `Point` onto this `ICurve`.

#### getTransformed

    public Line 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`
Overrides:
  `getTransformed` in class `BezierCurve`
Parameters:
  `t` - The `AffineTransform` to be applied
Returns:
  a transformed `Path` representation of this `IGeometry`
See Also:
  `IGeometry.getTransformed(AffineTransform)`

#### intersects

    public boolean intersects​(ICurve c)

Description copied from interface: `ICurve`
Tests if this `ICurve` and the given `ICurve` intersect, i.e. whether a final set of intersection points exists. Two curves intersect if they touch (see `IGeometry.touches(IGeometry)`) but do not overlap (see `ICurve.overlaps(ICurve)`).

Specified by:
  `intersects` in interface `ICurve`
Overrides:
  `intersects` in class `BezierCurve`
Parameters:
  `c` - The `ICurve` to test for intersections.
Returns:
  `true` if they intersect, `false` otherwise

#### intersects

    public boolean intersects​(Line l)

Provides an optimized version of the `BezierCurve.intersects(ICurve)` method.

Parameters:
  `l` - The `Line` to test for intersections.
Returns:
  see `BezierCurve.intersects(ICurve)`

#### overlaps

    public boolean overlaps​(BezierCurve c)

Description copied from class: `BezierCurve`
Checks if this `BezierCurve` and the given other `BezierCurve` overlap, i.e. an infinite set of intersection `Point`s exists.

Overrides:
  `overlaps` in class `BezierCurve`
Parameters:
  `c` - the `BezierCurve` to check for an overlapping segment with this `BezierCurve`
Returns:
  `true` if this and the given other `BezierCurve` overlap, otherwise `false`

#### overlaps

    public boolean overlaps​(Line l)

Tests whether this `Line` and the given other `Line` overlap, i.e. they share an infinite number of `Point`s.

Parameters:
  `l` - the other `Line` to test for overlap with this `Line`
Returns:
  `true` if this `Line` and the other `Line` overlap, otherwise `false`
See Also:
  `ICurve.overlaps(ICurve)`

#### setLine

    public Line setLine​(double x1,
                        double y1,
                        double x2,
                        double y2)

Initializes this `Line` with the given start and end point coordinates

Parameters:
  `x1` - the x-coordinate of the start point
  `y1` - the y-coordinate of the start point
  `x2` - the x-coordinate of the end point
  `y2` - the y-coordinate of the end point
Returns:
  `this` for convenience

#### setLine

    public Line setLine​(Line l)

Initializes this `Line` with the start and end point coordinates of the given one.

Parameters:
  `l` - the `Line` whose start and end point coordinates should be used for initialization
Returns:
  `this` for convenience

#### setLine

    public Line setLine​(Point p1,
                        Point p2)

Initializes this `Line` with the start and end point coordinates provided by the given points

Parameters:
  `p1` - the Point whose coordinates should be used as the start point coordinates of this `Line`
  `p2` - the Point whose coordinates should be used as the end point coordinates of this `Line`
Returns:
  `this` for convenience

#### setX1

    public Line setX1​(double x1)

Sets the x-coordinate of the start `Point` of this `Line` to the given value.

Parameters:
  `x1` - The new x-coordinate for the start `Point` of this `Line`.
Returns:
  `this` for convenience

#### setX2

    public Line setX2​(double x2)

Sets the x-coordinate of the end `Point` of this `Line` to the given value.

Parameters:
  `x2` - The new x-coordiante for the end `Point` of this `Line`.
Returns:
  `this` for convenience

#### setY1

    public Line setY1​(double y1)

Sets the y-coordinate of the start `Point` of this `Line` to the given value.

Parameters:
  `y1` - The new y-coordinate for the start `Point` of this `Line`.
Returns:
  `this` for convenience

#### setY2

    public Line setY2​(double y2)

Sets the y-coordinate of the end `Point` of this `Line` to the given value.

Parameters:
  `y2` - The new y-coordinate for the end `Point` of this `Line`.
Returns:
  `this` for convenience

#### toPath

    public Path toPath()

Description copied from class: `BezierCurve`
Returns a `Path` approximating this `BezierCurve` using `Line` segments.

Specified by:
  `toPath` in interface `IGeometry`
Overrides:
  `toPath` in class `BezierCurve`
Returns:
  a `Path` approximating this `BezierCurve` using `Line` segments

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `BezierCurve`

#### 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.

#### touches

    public boolean touches​(Line l)

Tests whether this `Line` and the given one share at least one common point.

Parameters:
  `l` - The `Line` to test.
Returns:
  `true` if this `Line` and the given one share at least one common point, `false` otherwise.

#### clone

    public java.lang.Object clone()

Overridden with public visibility as recommended within `Cloneable` .

Overrides:
  `clone` in class `java.lang.Object`

#### hashCode

    public final int hashCode()

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