Class GridPoint

java.lang.Object
Jcg.geometry.GridPoint

public class GridPoint extends Object
A class for representing a 2D point (a cell) on an integer grid.
Author:
Luca Castelli Aleardi (jan 2021)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    an integer useful for indexing this point: for instance, 'index' can be the number of a vertex
    private int
    integer coordinates of the point on the grid
    private int
    integer coordinates of the point on the grid
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialize an empty point
    GridPoint(int x, int y)
    Initialize an integer point having coordinates (x, y)
    Make a copy of a point q
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    boolean
    Check whether two points have equal coordinates
    double
    Return the Euclidean distance between the current point 'this' and a point 'p'
    int
    getCartesian(int dim)
    Return the d-th coordinate of the point
    int
    Return the x-coordinate
    int
    Return the y-coordinate
    int
     
    int
    Return the Manhattan distance between the current point 'this' and a point 'p'
    void
    setCartesian(int dim, int x)
    Set the d-th coordinate of the point
    void
     
    void
    setX(int x)
    Set the x-coordinate
    void
    setY(int y)
    Set the y-coordinate
    int
    Return the square of the Euclidean distance between the current point 'this' and a point 'p'
     
    void
    translateOf(int dx, int dy)
    Translate the current point of the vector (dx, dy)

    Methods inherited from class java.lang.Object

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

    • index

      public int index
      an integer useful for indexing this point: for instance, 'index' can be the number of a vertex
    • x

      private int x
      integer coordinates of the point on the grid
    • y

      private int y
      integer coordinates of the point on the grid
  • Constructor Details

    • GridPoint

      public GridPoint()
      Initialize an empty point
    • GridPoint

      public GridPoint(int x, int y)
      Initialize an integer point having coordinates (x, y)
    • GridPoint

      public GridPoint(GridPoint p)
      Make a copy of a point q
  • Method Details

    • getX

      public int getX()
      Return the x-coordinate
    • getY

      public int getY()
      Return the y-coordinate
    • setX

      public void setX(int x)
      Set the x-coordinate
    • setY

      public void setY(int y)
      Set the y-coordinate
    • translateOf

      public void translateOf(int dx, int dy)
      Translate the current point of the vector (dx, dy)
    • equals

      public boolean equals(Object o)
      Check whether two points have equal coordinates
      Overrides:
      equals in class Object
    • hashCode

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

      public double euclideanDistance(GridPoint p)
      Return the Euclidean distance between the current point 'this' and a point 'p'
    • manhattanDistance

      public int manhattanDistance(GridPoint p)
      Return the Manhattan distance between the current point 'this' and a point 'p'
    • squareEuclideanDistance

      public int squareEuclideanDistance(GridPoint p)
      Return the square of the Euclidean distance between the current point 'this' and a point 'p'
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dimension

      public int dimension()
    • getCartesian

      public int getCartesian(int dim)
      Return the d-th coordinate of the point
    • setCartesian

      public void setCartesian(int dim, int x)
      Set the d-th coordinate of the point
    • setOrigin

      public void setOrigin()