class

PointClickEngine::Navigation::PathOptimizer

Inherits Reference < Object

Optimizes paths by removing redundant waypoints and smoothing

The PathOptimizer improves pathfinding results by removing unnecessary intermediate points while maintaining path validity. It uses line-of-sight checks to determine when waypoints can be safely removed.

Constructors

new(grid : NavigationGrid, max_lookahead : Int32 = PointClickEngine::Core::GameConstants::PATH_OPTIMIZATION_MAX_LOOKAHEAD, midpoint_threshold : Int32 = PointClickEngine::Core::GameConstants::PATH_MIDPOINT_INSERTION_THRESHOLD, preserve_intermediate_points : Bool = true)
Source

Instance methods

aggressive_optimize(path : Array(RL::Vector2)) : Array(RL::Vector2)

Aggressively optimizes path by removing as many points as possible

Source
calculate_path_length(path : Array(RL::Vector2)) : Float32

Calculates path length

Source
conservative_optimize(path : Array(RL::Vector2)) : Array(RL::Vector2)

Conservative optimization that keeps more intermediate points

Source
densify_path(path : Array(RL::Vector2), max_segment_length : Float32) : Array(RL::Vector2)

Inserts intermediate points for smoother movement

Source
find_closest_point_on_path(path : Array(RL::Vector2), position : RL::Vector2) : NamedTuple(point: RL::Vector2, index: Int32, distance: Float32)

Finds the closest point on path to a given position

Source
get_optimization_stats(original : Array(RL::Vector2), optimized : Array(RL::Vector2)) : Hash(String, Float32)

Gets optimization statistics

Source
grid
Source
grid=(grid : NavigationGrid)
Source
has_clear_path(start : RL::Vector2, target : RL::Vector2) : Bool

Checks if there's a clear path between two points using Bresenham's line algorithm

Source
has_clear_path_precise(start : RL::Vector2, target : RL::Vector2, samples : Int32 = 10) : Bool

Checks line of sight with sub-grid precision

Source
is_path_valid?(path : Array(RL::Vector2)) : Bool

Validates if a path is still walkable

Source
max_lookahead
Source
max_lookahead=(max_lookahead : Int32)
Source
midpoint_threshold
Source
midpoint_threshold=(midpoint_threshold : Int32)
Source
optimize_path(path : Array(RL::Vector2)) : Array(RL::Vector2)

Optimizes a path by removing redundant waypoints

Source
preserve_intermediate_points
Source
preserve_intermediate_points=(preserve_intermediate_points : Bool)
Source
simplify_path(path : Array(RL::Vector2), min_distance : Float32) : Array(RL::Vector2)

Removes points that are too close together

Source
smooth_path(path : Array(RL::Vector2), smoothing_factor : Float32 = 0.5_f32) : Array(RL::Vector2)

Smooths path using spline-like interpolation

Source
to_s(io : IO) : Nil

String representation

Source