Class Line

All Implemented Interfaces:
Serializable, 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:
  • Constructor Details

    • 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:
    • Line

      public Line(double x1, double y1, double x2, double y2)
      Constructs a new Line, which connects the two Points 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 Points 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 Points
      Parameters:
      p1 - the start point
      p2 - the end point
  • Method Details

    • 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:
    • 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 Points of intersection of this and the given other BezierCurve.
      Overrides:
      getIntersections in class BezierCurve
      Parameters:
      curve - the BezierCurve which is searched for Points of intersection with this BezierCurve
      Returns:
      the Points 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:
    • getPoints

      public Point[] getPoints()
      Returns an array, which contains two Points representing the start and end points of this Line
      Overrides:
      getPoints in class BezierCurve
      Returns:
      an array with two Points, 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:
    • 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 Points 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 Points.
      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:
    • 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 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 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: