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.
Instance methods
aggressive_optimize(path : Array(RL::Vector2)) : Array(RL::Vector2)
Aggressively optimizes path by removing as many points as possible
Sourcecalculate_path_length(path : Array(RL::Vector2)) : Float32
Sourceconservative_optimize(path : Array(RL::Vector2)) : Array(RL::Vector2)
Conservative optimization that keeps more intermediate points
Sourcedensify_path(path : Array(RL::Vector2), max_segment_length : Float32) : Array(RL::Vector2)
Inserts intermediate points for smoother movement
Sourcefind_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
Sourceget_optimization_stats(original : Array(RL::Vector2), optimized : Array(RL::Vector2)) : Hash(String, Float32)
Gets optimization statistics
Sourcegrid=(grid : NavigationGrid)
Sourcehas_clear_path(start : RL::Vector2, target : RL::Vector2) : Bool
Checks if there's a clear path between two points using Bresenham's line algorithm
Sourcehas_clear_path_precise(start : RL::Vector2, target : RL::Vector2, samples : Int32 = 10) : Bool
Checks line of sight with sub-grid precision
Sourceis_path_valid?(path : Array(RL::Vector2)) : Bool
Validates if a path is still walkable
Sourcemax_lookahead=(max_lookahead : Int32)
Sourcemidpoint_threshold=(midpoint_threshold : Int32)
Sourceoptimize_path(path : Array(RL::Vector2)) : Array(RL::Vector2)
Optimizes a path by removing redundant waypoints
Sourcesimplify_path(path : Array(RL::Vector2), min_distance : Float32) : Array(RL::Vector2)
Removes points that are too close together
Sourcesmooth_path(path : Array(RL::Vector2), smoothing_factor : Float32 = 0.5_f32) : Array(RL::Vector2)
Smooths path using spline-like interpolation
Source