Package ch.epfl.cs107.play.math
Class DiscreteCoordinates
java.lang.Object
ch.epfl.cs107.play.math.DiscreteCoordinates
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic floatReturn the euclidean Distance between two discrete coordinatedown()booleanReturn the neighbours coordinatesinthashCode()static booleanCheck weather a vector is close enough from any coordinate crossingstatic booleanCheck weather a vector is close enough from a specific coordinate crossingjump(int dx, int dy) Make a jump to another cellMake a jump to another cellleft()right()toString()toVector()up()
-
Field Details
-
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 indexy- (int): The row index
-
-
Method Details
-
left
- Returns:
- (DiscreteCoordinates): one coordinate left
-
right
- Returns:
- (DiscreteCoordinates): one coordinate right
-
up
- Returns:
- (DiscreteCoordinates): one coordinate above
-
down
- Returns:
- (DiscreteCoordinates): one coordinate below
-
getNeighbours
Return the neighbours coordinates- Returns:
- (float): the neighbours
-
jump
Make a jump to another cell- Parameters:
dx- (int): the delta xdy- (int): the delta y- Returns:
- (DiscreteCoordinates): the Coordinates after the jump
-
jump
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
- Returns:
- (Vector): convert coordinates into continuous vector
-
isCoordinates
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
Check weather a vector is close enough from a specific coordinate crossing- Parameters:
v- (Vector): the vector to check. Not nullc- (DiscreteCoordinates): the discrete coordinate to compare with- Returns:
- (boolean) : true if the given vector is close enough from the given coordinate
-
distanceBetween
Return the euclidean Distance between two discrete coordinate- Parameters:
a- (DiscreteCoordinates). Not nullb- (DiscreteCoordinates). Not null- Returns:
- (float): the euclidean distance between the two coordinates
-
hashCode
public int hashCode() -
equals
-
toString
-