Package edu.uoc.pacman.model.utils
Class Position
java.lang.Object
edu.uoc.pacman.model.utils.Position
Stores a 2D position/point/coordinate.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Position
Creates a newPosition
object as a result to addp1
andp2
.double
Calculates the Euclidean distance from this point to other given point.boolean
Checks if two positions are equal.int
getX()
Getter of the attributex
int
getY()
Getter of the attributey
int
hashCode()
Returns the hash of aPosition
object.void
setX
(int x) Setter of the attributex
void
setY
(int y) Setter of the attributey
toString()
Returns a comma-seperated string representation of a Position.
Format: "x,y"
Example: "3,4"
-
Field Details
-
x
private int xValue of the attribute X axis -
y
private int yValue of the attribute Y axis
-
-
Constructor Details
-
Position
public Position(int x, int y) Constructor with arguments.- Parameters:
x
- Initial value of the attributex
y
- Initial value of the attributey
-
-
Method Details
-
getX
public int getX()Getter of the attributex
- Returns:
- The current value of the attribute
x
-
setX
public void setX(int x) Setter of the attributex
- Parameters:
x
- New value for the attributex
-
getY
public int getY()Getter of the attributey
- Returns:
- The current value of the attribute
y
-
setY
public void setY(int y) Setter of the attributey
- Parameters:
y
- New value for the attributey
-
distance
Calculates the Euclidean distance from this point to other given point.- Parameters:
other
- Second position to calculate distance.- Returns:
- The Euclidean distance between the position which invokes the method
and the
other
position. Ifother
isnull
, then it returns 0.
-
add
Creates a newPosition
object as a result to addp1
andp2
.- Parameters:
p1
- First positionp2
- Second position- Returns:
- New
Position
with x = p1.x + p2.x and y = p1.y and p2.y. - Throws:
NullPointerException
- When eitherp1
orp2
arenull
.
-
equals
Checks if two positions are equal. -
hashCode
public int hashCode()Returns the hash of aPosition
object. -
toString
Returns a comma-seperated string representation of a Position.
Format: "x,y"
Example: "3,4"
-