Package de.bsommerfeld.pathetic.engine
Class Node
java.lang.Object
de.bsommerfeld.pathetic.engine.Node
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionNode(PathPosition position, PathPosition start, PathPosition target, HeuristicWeights heuristicWeights, IHeuristicStrategy heuristicStrategy, int depth) Creates a new Node with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionintbooleanintgetDepth()doublegetFCost()Calculates the estimated total cost (F-cost) of the path from the start node to the target node, passing through this node.doublegetGCost()Gets the calculated G-cost (accumulated known cost from the start node) for this node.getStart()inthashCode()booleanisTarget()voidsetGCost(double gCost) Sets the calculated G-cost for this node.void
-
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 nodestart- The start position of the pathtarget- The target position of the pathheuristicWeights- The weights to apply to different heuristic componentsheuristicStrategy- The mode of heuristic calculation (PERFORMANCE or PRECISION)depth- The depth of this node in the search tree
-
-
Method Details
-
getPosition
-
getStart
-
getTarget
-
getHeuristic
-
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
-
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
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Node>
-