Class GLine

java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GLine
All Implemented Interfaces:
Cloneable

public class GLine extends GraphicE
This class represents a line segment
Author:
Federico Vera <[email protected]>
  • Field Summary

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • Constructor Summary

    Constructors
    Constructor
    Description
    GLine(int x, int y, double length, double angle)
    Constructs a new line based on its start point, length and angle
    GLine(int x1, int y1, int x2, int y2)
    Constructs a new line segment based on the end points
    Copy constructor
    GLine(GPoint p1, GPoint p2)
    Constructs a new line segment based on the end points
  • Method Summary

    Modifier and Type
    Method
    Description
     
    boolean
    contains(int x, int y)
    Tells if a point is contained in this line segment
    boolean
    Tells if a point is contained in this line segment
    void
    Draws the component on the given graphics
    boolean
     
    double
    Retrieves the argument of the line segment (in degrees)
    Retrieves a copy of the end point of this line segment
    Retrieves the middle point of the line
    Retrieves an orthogonal line that segment contains (0, 0) as it's start point
    getOrthogal(int x, int y)
    Retrieves an orthogonal line segment that contains (x, y) as it's start point
    getParallel(int x, int y)
    Retrieves an parallel line segment that contains (x, y) as it's start point
    double
    Retrieves the argument of the line segment (in radians)
    Retrieves a copy of the start point of this line segment
    int
     
    double
    Retrieves the length of the line segment
    void
    traslate(int x, int y)
    Traslates this element on X and Y

    Methods inherited from class com.dkt.graphics.elements.GraphicE

    getPaint, getStroke, setPaint, setStroke

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GLine

      public GLine(GLine e)
      Copy constructor
      Parameters:
      e - GLine to copy
      Throws:
      IllegalArgumentException - if e is null
    • GLine

      public GLine(GPoint p1, GPoint p2) throws IllegalArgumentException
      Constructs a new line segment based on the end points
      Parameters:
      p1 - start point
      p2 - end point
      Throws:
      IllegalArgumentException
    • GLine

      public GLine(int x1, int y1, int x2, int y2)
      Constructs a new line segment based on the end points
      Parameters:
      x1 - x coordinate of the start point
      y1 - y coordinate of the start point
      x2 - x coordinate of the end point
      y2 - y coordinate of the end point
    • GLine

      public GLine(int x, int y, double length, double angle)
      Constructs a new line based on its start point, length and angle
      Parameters:
      x - x coordinate of the start point
      y - y coordinate of the start point
      length - length of the vector
      angle - angle (in degrees) of the line segment
  • Method Details

    • getMiddlePoint

      public GPoint getMiddlePoint()
      Retrieves the middle point of the line
      Returns:
      middle point
    • getOrthogal

      public GLine getOrthogal()
      Retrieves an orthogonal line that segment contains (0, 0) as it's start point
      Returns:
      Orthogonal GLine
    • getOrthogal

      public GLine getOrthogal(int x, int y)
      Retrieves an orthogonal line segment that contains (x, y) as it's start point
      Parameters:
      x - x coordinate of the start point
      y - y coordinate of the start point
      Returns:
      Orthogonal GLine
    • getParallel

      public GLine getParallel(int x, int y)
      Retrieves an parallel line segment that contains (x, y) as it's start point
      Parameters:
      x - x coordinate of the start point
      y - y coordinate of the start point
      Returns:
      Orthogonal GLine
    • getStartPoint

      public GPoint getStartPoint()
      Retrieves a copy of the start point of this line segment
      Returns:
      start GPoint of the line segment
    • getEndPoint

      public GPoint getEndPoint()
      Retrieves a copy of the end point of this line segment
      Returns:
      end GPoint of the line segment
    • getRadArgument

      public double getRadArgument()
      Retrieves the argument of the line segment (in radians)
      Returns:
      angle in radians
    • getArgument

      public double getArgument()
      Retrieves the argument of the line segment (in degrees)
      Returns:
      angle in degrees
    • modulus

      public double modulus()
      Retrieves the length of the line segment
      Returns:
      length
    • contains

      public boolean contains(GPoint p)
      Tells if a point is contained in this line segment
      Parameters:
      p - point to check
      Returns:
      true if the point is contained in the segment and false otherwise
      Throws:
      IllegalArgumentException - if p is null
    • contains

      public boolean contains(int x, int y)
      Tells if a point is contained in this line segment
      Parameters:
      x - the X coordinate of the point
      y - the Y coordinate of the point
      Returns:
      true if the point is contained in the segment and false otherwise
    • draw

      public void draw(Graphics2D g)
      Description copied from class: GraphicE
      Draws the component on the given graphics
      Specified by:
      draw in class GraphicE
      Parameters:
      g - where to draw
    • traslate

      public void traslate(int x, int y)
      Description copied from class: GraphicE
      Traslates this element on X and Y
      Specified by:
      traslate in class GraphicE
      Parameters:
      x - size in px of the horizontal translation
      y - size in px of the vertical translation
    • clone

      public GLine clone()
      Specified by:
      clone in class GraphicE
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GraphicE
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GraphicE