Class DiscreteCoordinates

java.lang.Object
ch.epfl.cs107.play.math.DiscreteCoordinates
All Implemented Interfaces:
Serializable

public final class DiscreteCoordinates extends Object implements Serializable
DiscreteCoordinates assume a standard coordinate system. Assume every unit the coordinate axis are graduated. Now imagine a grid passing by all graduation. We get the set of all discrete coordinates: For example if x, y in [0, 2] we get: (0, 0), (1, 0), (2, 0), (0, 1) (0, 2), (1, 1), (1, 2), (2, 1), (2, 2) DiscreteCoordinate are special Vector that can be assimilated to Cells in a grid in a way DiscreteCoordinate (1, 1) include all vector (x, y) with x, y in [1; 2)
See Also:
  • Field Details

    • ORIGIN

      public static DiscreteCoordinates ORIGIN
    • x

      public final int x
    • y

      public final int y
  • Constructor Details

    • DiscreteCoordinates

      public DiscreteCoordinates(int x, int y)
      Default coordinate constructor
      Parameters:
      x - (int): The column index
      y - (int): The row index
  • Method Details

    • left

      public DiscreteCoordinates left()
      Returns:
      (DiscreteCoordinates): one coordinate left
    • right

      public DiscreteCoordinates right()
      Returns:
      (DiscreteCoordinates): one coordinate right
    • up

      public DiscreteCoordinates up()
      Returns:
      (DiscreteCoordinates): one coordinate above
    • down

      public DiscreteCoordinates down()
      Returns:
      (DiscreteCoordinates): one coordinate below
    • getNeighbours

      public List<DiscreteCoordinates> getNeighbours()
      Return the neighbours coordinates
      Returns:
      (float): the neighbours
    • jump

      public DiscreteCoordinates jump(int dx, int dy)
      Make a jump to another cell
      Parameters:
      dx - (int): the delta x
      dy - (int): the delta y
      Returns:
      (DiscreteCoordinates): the Coordinates after the jump
    • jump

      public DiscreteCoordinates jump(Vector delta)
      Make a jump to another cell
      Parameters:
      delta - (Vector): to define the length and the direction of the jump. Not null
      Returns:
      (DiscreteCoordinates): the Coordinates after the jump
    • toVector

      public Vector toVector()
      Returns:
      (Vector): convert coordinates into continuous vector
    • isCoordinates

      public static boolean isCoordinates(Vector v)
      Check weather a vector is close enough from any coordinate crossing
      Parameters:
      v - (Vector): the vector to check. Not null
      Returns:
      (boolean): true if the given vector is close enough from a coordinate
    • isCoordinates

      public static boolean isCoordinates(Vector v, DiscreteCoordinates c)
      Check weather a vector is close enough from a specific coordinate crossing
      Parameters:
      v - (Vector): the vector to check. Not null
      c - (DiscreteCoordinates): the discrete coordinate to compare with
      Returns:
      (boolean) : true if the given vector is close enough from the given coordinate
    • distanceBetween

      public static float distanceBetween(DiscreteCoordinates a, DiscreteCoordinates b)
      Return the euclidean Distance between two discrete coordinate
      Parameters:
      a - (DiscreteCoordinates). Not null
      b - (DiscreteCoordinates). Not null
      Returns:
      (float): the euclidean distance between the two coordinates
    • hashCode

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

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object