Class Line

java.lang.Object
com.nomagic.awt.Line

@OpenApiAll public class Line extends Object
The Line represents a line segment in (x, y) coordinate space.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The first point of the line.
    The second point of the line.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new line whose first point is at (0,0) in the coordinate space, and whose second point is at (0, 0) in the coordinate space.
    Line(int x1, int y1, int x2, int y2)
    Constructs a new line whose first point is specified as (xy) and whose second point is specified as (xy).
    Constructs a new line, initialized to match the values of the specified line.
    Line(Point p1, Point p2)
    Constructs a new line whose first point is specified as p1 and whose second point is specified as p2.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether specified point belongs to this line.
    boolean
    Checks whether two lines are equal.
    Gets the bounding rectangle of this line.
    int
     
    Computes the intersection of this line with the specified line.
    Computes the intersection of this line with the line perpendicular to this line.
    boolean
    Determines whether this line and the specified line intersect.
    boolean
     
    Returns a string representation of this line and its values.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • A

      public Point A
      The first point of the line.
    • B

      public Point B
      The second point of the line.
  • Constructor Details

    • Line

      public Line()
      Constructs a new line whose first point is at (0,0) in the coordinate space, and whose second point is at (0, 0) in the coordinate space.
    • Line

      public Line(Line l)
      Constructs a new line, initialized to match the values of the specified line.
      Parameters:
      l - a line from which to copy initial values.
    • Line

      public Line(Point p1, Point p2)
      Constructs a new line whose first point is specified as p1 and whose second point is specified as p2.
      Parameters:
      p1 - the first point.
      p2 - the second point.
    • Line

      public Line(int x1, int y1, int x2, int y2)
      Constructs a new line whose first point is specified as (xy) and whose second point is specified as (xy).
      Parameters:
      x1 - the first point x coordinate.
      y1 - the first point y coordinate.
      x2 - the second point x coordinate.
      y2 - the second point y coordinate.
  • Method Details

    • intersects

      public boolean intersects(Line l)
      Determines whether this line and the specified line intersect.
      Parameters:
      l - a line.
      Returns:
      true if the specified line and this line insersect; false otherwise.
    • intersection

      @CheckForNull public Point intersection(Line l)
      Computes the intersection of this line with the specified line. Returns a new point that represents the intersection of the two lines.
      Parameters:
      l - a line.
      Returns:
      the lines intersection point
    • intersection

      @CheckForNull public Point intersection(Point p)
      Computes the intersection of this line with the line perpendicular to this line. Perpendicular line go throught specified point. Returns a new point that represents the intersection of the two lines.
      Parameters:
      p - a point.
      Returns:
      the lines intersection point
    • belongs

      public boolean belongs(Point p)
      Checks whether specified point belongs to this line.

      The result is true if and only if the argument is not null and belongs to this line.

      Parameters:
      p - a point.
      Returns:
      true if specified point belongs to this line; false otherwise.
    • equals

      public boolean equals(Object obj)
      Checks whether two lines are equal.

      The result is true if and only if the argument is not null and is a Line object that has the same first point and second point as this line.

      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with.
      Returns:
      true if the objects are equal; false otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @OpenApi public String toString()
      Returns a string representation of this line and its values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this line.
    • getBounds

      public Rectangle getBounds()
      Gets the bounding rectangle of this line.

      This method is included for completeness, to parallel the getBounds method of Component.

      Returns:
      a new rectangle, equal to the bounding rectangle for this line.
      See Also:
    • isVertical

      public boolean isVertical()
      Returns:
      true if line is more vertical than horizontal.