Class GPoint

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

public class GPoint extends GraphicE
This class represents a mutable point
Author:
Federico Vera <[email protected]>
  • Field Summary

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

    STROKE
  • 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
    Copy constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    ccw(GPoint a, GPoint b, GPoint c)
    Is a->b->c a counterclockwise (levorotary) turn?
     
    double
    distance(int x, int y)
    Calculates the distance between this point and the one passed as an argument
    double
    Calculates the distance between this point and the one passed as an argument
    void
    Draws the component on the given graphics
    boolean
     
    int
     
    void
    move(int x, int y)
    Moves this point to the given coordinates
     
    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 com.dkt.graphics.elements.GraphicE

    getPaint, getStroke, setPaint, setStroke

    Methods inherited from class java.lang.Object

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

    • GPoint

      public GPoint(GPoint e)
      Copy constructor
      Parameters:
      e - GPoint to copy
      Throws:
      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 Details

    • 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:
      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(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 String toString()
      Overrides:
      toString in class Object
    • clone

      public GPoint 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