Class GLine

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class GLine
    extends GraphicE
    This class represents a line segment
    • Field Summary

    • 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
      GLine​(GLine e)
      Copy constructor
      GLine​(GPoint p1, GPoint p2)
      Constructs a new line segment based on the end points
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GLine clone()  
      boolean contains​(int x, int y)
      Tells if a point is contained in this line segment
      boolean contains​(GPoint p)
      Tells if a point is contained in this line segment
      void draw​(java.awt.Graphics2D g)
      Draws the component on the given graphics
      boolean equals​(java.lang.Object obj)  
      double getArgument()
      Retrieves the argument of the line segment (in degrees)
      GPoint getEndPoint()
      Retrieves a copy of the end point of this line segment
      GPoint getMiddlePoint()
      Retrieves the middle point of the line
      GLine getOrthogal()
      Retrieves an orthogonal line that segment contains (0, 0) as it's start point
      GLine getOrthogal​(int x, int y)
      Retrieves an orthogonal line segment that contains (x, y) as it's start point
      GLine getParallel​(int x, int y)
      Retrieves an parallel line segment that contains (x, y) as it's start point
      double getRadArgument()
      Retrieves the argument of the line segment (in radians)
      GPoint getStartPoint()
      Retrieves a copy of the start point of this line segment
      int hashCode()  
      double modulus()
      Retrieves the length of the line segment
      void traslate​(int x, int y)
      Traslates this element on X and Y
      • Methods inherited from class java.lang.Object

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

      • GLine

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

        public GLine​(GPoint p1,
                     GPoint p2)
              throws java.lang.IllegalArgumentException
        Constructs a new line segment based on the end points
        Parameters:
        p1 - start point
        p2 - end point
        Throws:
        java.lang.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 Detail

      • 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:
        java.lang.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​(java.awt.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
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class GraphicE