Class GPoint

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class GPoint
    extends GraphicE
    This class represents a mutable point
    • Field Summary

    • Constructor Summary

      Constructors 
      Constructor Description
      GPoint​(int x, int y)
      Creates a new GPoint
      GPoint​(int x, int y, int cs)
      Creates a new GPoint with a given cross size
      GPoint​(GPoint e)
      Copy constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int ccw​(GPoint a, GPoint b, GPoint c)
      Is a->b->c a counterclockwise (levorotary) turn?
      GPoint clone()  
      double distance​(int x, int y)
      Calculates the distance between this point and the one passed as an argument
      double distance​(GPoint p)
      Calculates the distance between this point and the one passed as an argument
      void draw​(java.awt.Graphics2D g)
      Draws the component on the given graphics
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      void move​(int x, int y)
      Moves this point to the given coordinates
      java.lang.String toString()  
      void traslate​(int x, int y)
      Traslates this element on X and Y
      int x()
      Retrieves the X coordinate of this point
      int y()
      Retrieves the Y coordinate of this point
      • Methods inherited from class java.lang.Object

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

      • GPoint

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

        public GPoint​(int x,
                      int y)
        Creates a new GPoint
        Parameters:
        x - The x coordinate of the point
        y - The y coordinate of the point
      • GPoint

        public GPoint​(int x,
                      int y,
                      int cs)
        Creates a new GPoint with a given cross size
        Parameters:
        x - The x coordinate of the point
        y - The y coordinate of the point
        cs - Cross size
    • Method Detail

      • x

        public int x()
        Retrieves the X coordinate of this point
        Returns:
        x coordinate
      • y

        public int y()
        Retrieves the Y coordinate of this point
        Returns:
        y coordinate
      • distance

        public double distance​(GPoint p)
        Calculates the distance between this point and the one passed as an argument
        Parameters:
        p - the reference point
        Returns:
        distance between points
        Throws:
        java.lang.IllegalArgumentException - if point is null
      • distance

        public double distance​(int x,
                               int y)
        Calculates the distance between this point and the one passed as an argument
        Parameters:
        x - the X coordinate of the point
        y - the Y coordinate of the point
        Returns:
        distance between points
      • ccw

        public static int ccw​(GPoint a,
                              GPoint b,
                              GPoint c)
        Is a->b->c a counterclockwise (levorotary) turn?
        Parameters:
        a - first point
        b - second point
        c - third point
        Returns:
        {-1, 0, +1} if a->b->c is respectively a clockwise, collinear; counterclockwise turn
      • 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
      • move

        public void move​(int x,
                         int y)
        Moves this point to the given coordinates
        Parameters:
        x - new x coordinate
        y - new y coordinate
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

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