Class PathPosition
java.lang.Object
de.metaphoriker.pathetic.api.wrapper.PathPosition
- All Implemented Interfaces:
Cloneable
Represents a position within a
PathEnvironment
. This class encapsulates the coordinates
(x, y, z) of a point in the pathfinding environment and provides methods for manipulating and
comparing positions.-
Constructor Summary
ConstructorsConstructorDescriptionPathPosition
(PathEnvironment pathEnvironment, double x, double y, double z) Constructs aPathPosition
with the specified environment and coordinates. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double x, double y, double z) Creates a newPathPosition
by adding the given values to the coordinates of this position.add
(PathVector vector) Creates a newPathPosition
by adding the components of the given vector to the coordinates of this position.clone()
double
distance
(PathPosition otherPosition) Calculates the Euclidean distance between this position and another position.double
distanceSquared
(PathPosition otherPosition) Calculates the squared distance between this position and another position.boolean
floor()
Creates a newPathPosition
with the same environment, but with the coordinates floored to the nearest integer values.int
Returns the x-coordinate of the block this position is located in.int
Returns the y-coordinate of the block this position is located in.int
Returns the z-coordinate of the block this position is located in.Returns the environment this position belongs to.double
getX()
Returns the x-coordinate of this position.double
getY()
Returns the y-coordinate of this position.double
getZ()
Returns the z-coordinate of this position.int
hashCode()
interpolate
(PathPosition other, double progress) Interpolates between this position and another position based on a given progress value.boolean
isInSameBlock
(PathPosition otherPosition) Checks if this position and another position are within the same block in the environment.int
manhattanDistance
(PathPosition otherPosition) Calculates the Manhattan distance between this position and another position.mid()
Creates a newPathPosition
with the same environment, but with the coordinates set to the center of the block they are in.midPoint
(PathPosition end) Calculates the midpoint between this position and another position.double
octileDistance
(PathPosition otherPosition) Calculates the Octile distance between this position and another position.setX
(double x) Creates a newPathPosition
with the same environment and coordinates as this one, but with the x-coordinate set to the given value.setY
(double y) Creates a newPathPosition
with the same environment and coordinates as this one, but with the y-coordinate set to the given value.setZ
(double z) Creates a newPathPosition
with the same environment and coordinates as this one, but with the z-coordinate set to the given value.subtract
(double x, double y, double z) Creates a newPathPosition
by subtracting the given values from the coordinates of this position.subtract
(PathVector vector) Creates a newPathPosition
by subtracting the components of the given vector from the coordinates of this position.toString()
toVector()
Creates a newPathVector
from the coordinates of this position.
-
Constructor Details
-
PathPosition
Constructs aPathPosition
with the specified environment and coordinates.- Parameters:
pathEnvironment
- The environment this position belongs to.x
- The x-coordinate of the position.y
- The y-coordinate of the position.z
- The z-coordinate of the position.
-
-
Method Details
-
interpolate
Interpolates between this position and another position based on a given progress value.- Parameters:
other
- The other position to interpolate towards.progress
- The interpolation progress, typically between 0.0 (this position) and 1.0 (other position).- Returns:
- A new
PathPosition
representing the interpolated point.
-
isInSameBlock
Checks if this position and another position are within the same block in the environment.- Parameters:
otherPosition
- The other position to compare with.- Returns:
true
if both positions share the same block coordinates (floored x, y, z values),false
otherwise.
-
manhattanDistance
Calculates the Manhattan distance between this position and another position. Manhattan distance is the sum of the absolute differences of their coordinates.- Parameters:
otherPosition
- The other position to calculate the distance to.- Returns:
- The Manhattan distance between the two positions.
-
octileDistance
Calculates the Octile distance between this position and another position. Octile distance is a more accurate approximation of diagonal distance in a grid-based environment compared to Manhattan distance.- Parameters:
otherPosition
- The other position to calculate the distance to.- Returns:
- The Octile distance between the two positions.
-
distanceSquared
Calculates the squared distance between this position and another position.- Parameters:
otherPosition
- The other position to calculate the distance to.- Returns:
- The squared distance between the two positions.
-
distance
Calculates the Euclidean distance between this position and another position.- Parameters:
otherPosition
- The other position to calculate the distance to.- Returns:
- The Euclidean distance between the two positions.
-
setX
Creates a newPathPosition
with the same environment and coordinates as this one, but with the x-coordinate set to the given value.- Parameters:
x
- The new x-coordinate.- Returns:
- A new
PathPosition
with the updated x-coordinate.
-
setY
Creates a newPathPosition
with the same environment and coordinates as this one, but with the y-coordinate set to the given value.- Parameters:
y
- The new y-coordinate.- Returns:
- A new
PathPosition
with the updated y-coordinate.
-
setZ
Creates a newPathPosition
with the same environment and coordinates as this one, but with the z-coordinate set to the given value.- Parameters:
z
- The new z-coordinate.- Returns:
- A new
PathPosition
with the updated z-coordinate.
-
getFlooredX
public int getFlooredX()Returns the x-coordinate of the block this position is located in. This is equivalent to flooring the x-coordinate.- Returns:
- The floored x-coordinate.
-
getFlooredY
public int getFlooredY()Returns the y-coordinate of the block this position is located in. This is equivalent to flooring the y-coordinate.- Returns:
- The floored y-coordinate.
-
getFlooredZ
public int getFlooredZ()Returns the z-coordinate of the block this position is located in. This is equivalent to flooring the z-coordinate.- Returns:
- The floored z-coordinate.
-
add
Creates a newPathPosition
by adding the given values to the coordinates of this position.- Parameters:
x
- The value to add to the x-coordinate.y
- The value to add to the y-coordinate.z
- The value to add to the z-coordinate.- Returns:
- A new
PathPosition
with the added values.
-
add
Creates a newPathPosition
by adding the components of the given vector to the coordinates of this position.- Parameters:
vector
- The vector to add.- Returns:
- A new
PathPosition
with the added vector components.
-
subtract
Creates a newPathPosition
by subtracting the given values from the coordinates of this position.- Parameters:
x
- The value to subtract from the x-coordinate.y
- The value to subtract from the y-coordinate.z
- The value to subtract from the z-coordinate.- Returns:
- A new
PathPosition
with the subtracted values.
-
subtract
Creates a newPathPosition
by subtracting the components of the given vector from the coordinates of this position.- Parameters:
vector
- The vector to subtract.- Returns:
- A new
PathPosition
with the subtracted vector components.
-
toVector
Creates a newPathVector
from the coordinates of this position.- Returns:
- A new
PathVector
representing this position's coordinates.
-
floor
Creates a newPathPosition
with the same environment, but with the coordinates floored to the nearest integer values.- Returns:
- A new
PathPosition
with floored coordinates.
-
mid
Creates a newPathPosition
with the same environment, but with the coordinates set to the center of the block they are in.- Returns:
- A new
PathPosition
at the center of the block.
-
midPoint
Calculates the midpoint between this position and another position.- Parameters:
end
- The other position to calculate the midpoint with.- Returns:
- A new
PathPosition
representing the midpoint.
-
clone
-
equals
-
hashCode
public int hashCode() -
getPathEnvironment
Returns the environment this position belongs to.- Returns:
- The
PathEnvironment
of this position.
-
getX
public double getX()Returns the x-coordinate of this position.- Returns:
- The x-coordinate.
-
getY
public double getY()Returns the y-coordinate of this position.- Returns:
- The y-coordinate.
-
getZ
public double getZ()Returns the z-coordinate of this position.- Returns:
- The z-coordinate.
-
toString
-