Class GridPoint_2

java.lang.Object
Jcg.geometry.GridPoint_2
All Implemented Interfaces:
Comparable<Point_>, Point_

public class GridPoint_2 extends Object implements Point_
A class for representing a 2D point on an integer grid.
Author:
Luca Castelli Aleardi (Ecole Polytechnique, december 2022)
  • Field Details

    • index

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

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

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

    • GridPoint_2

      public GridPoint_2()
      Initialize an empty point
    • GridPoint_2

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

      public GridPoint_2(int x, int y, int index)
      Initialize an integer point having coordinates (x, y), and with a given index
    • GridPoint_2

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

    • getIndex

      public int getIndex()
      Return the index
    • getX

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

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

      public void setIndex(int index)
      Set the index
    • setX

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

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

      public void translateOf(Vector_ o)
      Translate the current point of the vector o
      Specified by:
      translateOf in interface Point_
    • equals

      public boolean equals(Object o)
      Check whether the current point is equal to point 'o'.

      Warning: point 'o' must be of type GridPoint_2
      Overrides:
      equals in class Object
    • hashCode

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

      public double distanceFrom(GridPoint_2 p)
    • squareDistance

      public Integer squareDistance(Point_ p)
      Return the square of the Euclidean distance between the current point 'this' and a point p
      Specified by:
      squareDistance in interface Point_
    • barycenter

      public void barycenter(Point_[] points)
      Set the current point as the barycenter of an array of points
      Specified by:
      barycenter in interface Point_
    • linearCombination

      public void linearCombination(Point_[] points, Number[] coefficients)
      Set the current point to be the linear combination of the input points, with respect to the given input coefficients
      Specified by:
      linearCombination in interface Point_
    • linearCombination

      public static GridPoint_2 linearCombination(GridPoint_2[] points, Number[] coefficients)
      Return a new point defined by the linear combination of the input points, with respect to the given input coefficients
    • toString

      public String toString()
      Description copied from interface: Point_
      Return a string (representation of the point)
      Specified by:
      toString in interface Point_
      Overrides:
      toString in class Object
    • dimension

      public int dimension()
      Description copied from interface: Point_
      Return the dimension of the space
      Specified by:
      dimension in interface Point_
    • getCartesian

      public Integer getCartesian(int dim)
      Return the d-th coordinate of the point
      Specified by:
      getCartesian in interface Point_
      Parameters:
      dim - the d-th coordinate of the point:
      dim=0 for x-coordinate, dim=1 for y-coordinate
    • setCartesian

      public void setCartesian(int dim, Number x)
      Set the d-th coordinate of the point
      Specified by:
      setCartesian in interface Point_
      Parameters:
      dim - the d-th coordinate of the point:
      dim=0 for x-coordinate, dim=1 for y-coordinate
    • setOrigin

      public void setOrigin()
      Set the coordinates of the current point to be (0, 0)
      Specified by:
      setOrigin in interface Point_
    • minus

      public GridVector_2 minus(Point_ q)
      Return the integer grid vector (p-q), where q is the current point

      Warning: q is assumed to be an integer GridPoint_2
      Specified by:
      minus in interface Point_
      Returns:
      a new GridVector_2 vector corresponding to (p-q)
    • ccw

      public static boolean ccw(GridPoint_2 A, GridPoint_2 B, GridPoint_2 C)
      Returns:
      true if CAB is a positive angle
    • crossing

      public static boolean crossing(GridPoint_2 A, GridPoint_2 B, GridPoint_2 C, GridPoint_2 D)
      Returns:
      true if segments AB and CD intersect
    • crossingRect

      public static boolean crossingRect(GridPoint_2 A, GridPoint_2 B, GridPoint_2 C, GridPoint_2 D)
      Returns:
      true if segment AB intersects with rectangle defined by C and D
    • sum

      public GridPoint_2 sum(GridVector_2 v)
    • compareTo

      public int compareTo(Point_ q)
      Compare two points (lexicographic order on coordinates)
      Specified by:
      compareTo in interface Comparable<Point_>
      Parameters:
      q - the point to compare to the current point (this)
      Returns:
      -1 if the current point is smaller (with respect to lexicographic order) to the point q; it returns 0 is the two points have equal coordinates. It returns 1 otherwise.
    • compareCartesian

      public int compareCartesian(Point_ o, int i)
      Compare the i-th coordinate of two points
      Specified by:
      compareCartesian in interface Point_
      Parameters:
      o - the point to compare
      i - the i-th coordinate to compare
      Returns:
      -1 if the i-th coordinate of the current point this is smaller then i-th coordinate of point o, return 0 if both points have the same i-th coordinate, and return 1 otherwise