Class PathPosition

java.lang.Object
de.metaphoriker.pathetic.api.wrapper.PathPosition
All Implemented Interfaces:
Cloneable

public class PathPosition extends Object implements 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

    Constructors
    Constructor
    Description
    PathPosition(PathEnvironment pathEnvironment, double x, double y, double z)
    Constructs a PathPosition with the specified environment and coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double x, double y, double z)
    Creates a new PathPosition by adding the given values to the coordinates of this position.
    add(PathVector vector)
    Creates a new PathPosition by adding the components of the given vector to the coordinates of this position.
     
    double
    distance(PathPosition otherPosition)
    Calculates the Euclidean distance between this position and another position.
    double
    Calculates the squared distance between this position and another position.
    boolean
     
    Creates a new PathPosition 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
    Returns the x-coordinate of this position.
    double
    Returns the y-coordinate of this position.
    double
    Returns the z-coordinate of this position.
    int
     
    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
    Calculates the Manhattan distance between this position and another position.
    mid()
    Creates a new PathPosition with the same environment, but with the coordinates set to the center of the block they are in.
    Calculates the midpoint between this position and another position.
    double
    Calculates the Octile distance between this position and another position.
    setX(double x)
    Creates a new PathPosition with the same environment and coordinates as this one, but with the x-coordinate set to the given value.
    setY(double y)
    Creates a new PathPosition with the same environment and coordinates as this one, but with the y-coordinate set to the given value.
    setZ(double z)
    Creates a new PathPosition 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 new PathPosition by subtracting the given values from the coordinates of this position.
    Creates a new PathPosition by subtracting the components of the given vector from the coordinates of this position.
     
    Creates a new PathVector from the coordinates of this position.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PathPosition

      public PathPosition(PathEnvironment pathEnvironment, double x, double y, double z)
      Constructs a PathPosition 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

      public PathPosition interpolate(PathPosition other, double progress)
      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

      public boolean isInSameBlock(PathPosition otherPosition)
      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

      public int manhattanDistance(PathPosition otherPosition)
      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

      public double octileDistance(PathPosition otherPosition)
      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

      public double distanceSquared(PathPosition otherPosition)
      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

      public double distance(PathPosition otherPosition)
      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

      public PathPosition setX(double x)
      Creates a new PathPosition 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

      public PathPosition setY(double y)
      Creates a new PathPosition 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

      public PathPosition setZ(double z)
      Creates a new PathPosition 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

      public PathPosition add(double x, double y, double z)
      Creates a new PathPosition 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

      public PathPosition add(PathVector vector)
      Creates a new PathPosition 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

      public PathPosition subtract(double x, double y, double z)
      Creates a new PathPosition 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

      public PathPosition subtract(PathVector vector)
      Creates a new PathPosition 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

      public PathVector toVector()
      Creates a new PathVector from the coordinates of this position.
      Returns:
      A new PathVector representing this position's coordinates.
    • floor

      public PathPosition floor()
      Creates a new PathPosition with the same environment, but with the coordinates floored to the nearest integer values.
      Returns:
      A new PathPosition with floored coordinates.
    • mid

      public PathPosition mid()
      Creates a new PathPosition 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

      public PathPosition midPoint(PathPosition end)
      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

      public PathPosition clone()
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public PathEnvironment 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

      public String toString()
      Overrides:
      toString in class Object