Class HeuristicWeights

java.lang.Object
de.bsommerfeld.pathetic.api.pathing.heuristic.HeuristicWeights

public final class HeuristicWeights extends Object
Represents a set of weights used to calculate a heuristic for the A* pathfinding algorithm. These weights influence the prioritization of different path characteristics during the search.

This class defines weights for the following distance metrics:

  • Manhattan Distance: Prioritizes direct movement along axes.
  • Octile Distance: Allows for diagonal movement for finer-grained pathing.
  • Perpendicular Distance: Penalizes deviation from the straight line to the target, aiding in smoother paths.
  • Height Difference: Factors in elevation changes when calculating path costs.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final HeuristicWeights
    Represents the default set of heuristic weights used for pathfinding calculations.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(double manhattanWeight, double octileWeight, double perpendicularWeight, double heightWeight)
    Creates a new HeuristicWeights instance with the specified weights.
    boolean
     
    double
    Returns the weight applied to the height difference (elevation change) component of the heuristic.
    double
    Returns the weight applied to the Manhattan distance component of the heuristic.
    double
    Returns the weight applied to the Octile distance component of the heuristic.
    double
    Returns the weight applied to the perpendicular distance component of the heuristic.
    int
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_WEIGHTS

      public static final HeuristicWeights DEFAULT_WEIGHTS
      Represents the default set of heuristic weights used for pathfinding calculations. This instance is initialized with equal weights for all heuristic components: manhattanWeight, octileWeight, perpendicularWeight, and heightWeight, each set to 1.0.

      The DEFAULT_WEIGHTS instance prioritizes a balanced consideration of direct, axis-aligned movement, diagonal movement, path smoothness, and elevation changes.

  • Method Details

    • create

      public static HeuristicWeights create(double manhattanWeight, double octileWeight, double perpendicularWeight, double heightWeight)
      Creates a new HeuristicWeights instance with the specified weights.
      Parameters:
      manhattanWeight - The weight applied to the Manhattan distance component. A higher weight favours paths with a greater emphasis on direct, axis-aligned movement.
      octileWeight - The weight applied to the Octile distance component. A higher weight allows diagonal movement, enabling more flexible paths in 3D environments.
      perpendicularWeight - The weight applied to the perpendicular distance component. Increased weight discourages deviations from the straight line between the start and target, resulting in smoother paths.
      heightWeight - The weight applied to the height difference (elevation change) component. A higher weight gives more consideration to vertical distance, important for terrains with varying verticality.
      Returns:
      A new HeuristicWeights instance with the given weights.
    • getManhattanWeight

      public double getManhattanWeight()
      Returns the weight applied to the Manhattan distance component of the heuristic.
      Returns:
      The Manhattan distance weight.
    • getOctileWeight

      public double getOctileWeight()
      Returns the weight applied to the Octile distance component of the heuristic.
      Returns:
      The Octile distance weight.
    • getPerpendicularWeight

      public double getPerpendicularWeight()
      Returns the weight applied to the perpendicular distance component of the heuristic.
      Returns:
      The perpendicular distance weight.
    • getHeightWeight

      public double getHeightWeight()
      Returns the weight applied to the height difference (elevation change) component of the heuristic.
      Returns:
      The height difference weight.
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object