Class Node

java.lang.Object
de.bsommerfeld.pathetic.engine.Node
All Implemented Interfaces:
Comparable<Node>

public class Node extends Object implements Comparable<Node>
Represents a node in the pathfinding graph. Each node contains position information, references to start and target positions, and methods to calculate heuristic values for the A* algorithm.

The Node class supports two heuristic calculation modes:

  • PERFORMANCE: Uses squared distances to avoid expensive square root operations, resulting in faster computations at the cost of some precision.
  • PRECISION: Uses true linear distances for more accurate path calculations, which may be slightly slower due to square root operations.
  • Constructor Details

    • Node

      public Node(PathPosition position, PathPosition start, PathPosition target, HeuristicWeights heuristicWeights, IHeuristicStrategy heuristicStrategy, int depth)
      Creates a new Node with the specified parameters.
      Parameters:
      position - The position of this node
      start - The start position of the path
      target - The target position of the path
      heuristicWeights - The weights to apply to different heuristic components
      heuristicStrategy - The mode of heuristic calculation (PERFORMANCE or PRECISION)
      depth - The depth of this node in the search tree
  • Method Details

    • getPosition

      public PathPosition getPosition()
    • getStart

      public PathPosition getStart()
    • getTarget

      public PathPosition getTarget()
    • getHeuristic

      public ComputingCache<Double> getHeuristic()
    • getParent

      public Node getParent()
    • getDepth

      public int getDepth()
    • setGCost

      public void setGCost(double gCost)
      Sets the calculated G-cost for this node. This is typically called by the pathfinding algorithm after evaluating costs, including contributions from cost processors.
      Parameters:
      gCost - The G-cost (accumulated cost from the start node).
    • setParent

      public void setParent(Node parent)
    • isTarget

      public boolean isTarget()
    • getFCost

      public double getFCost()
      Calculates the estimated total cost (F-cost) of the path from the start node to the target node, passing through this node. F-cost = G-cost + H-cost.
      Returns:
      The estimated total cost.
    • getGCost

      public double getGCost()
      Gets the calculated G-cost (accumulated known cost from the start node) for this node. This value is set by the pathfinding algorithm.
      Returns:
      The G-cost.
    • equals

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

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

      public int compareTo(Node o)
      Specified by:
      compareTo in interface Comparable<Node>