Class PathUtils
Path objects.
All methods are static, immutable (return new paths), and
use ArrayDeque internally for optimal performance when building sequences.
These operations are not part of core pathfinding but are essential for path refinement, visualization, animation, or coordinate transformation.
- Since:
- 5.3.3
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Pathinterpolate(Path path, double resolution) Interpolates a path by inserting intermediate positions between each pair of consecutive points.static PathConcatenates two paths into a single continuous path.static PathmutatePositions(Path path, ParameterizedSupplier<PathPosition> mutator) Applies a transformation function to every position in the path.static PathSimplifies a path by retaining only every nth point based on an epsilon value.static PathTruncates a path to a maximum number of positions.
-
Method Details
-
interpolate
Interpolates a path by inserting intermediate positions between each pair of consecutive points.For every segment from
starttoend, this method calculates the Euclidean distance and inserts points such that no two consecutive points are farther apart thanresolution.Useful for smooth movement, dense sampling, or visualization.
- Parameters:
path- the original path to interpolateresolution- the maximum allowed distance between any two consecutive points in the result- Returns:
- a new path with interpolated positions
- Throws:
IllegalArgumentException- ifresolution <= 0NullPointerException- ifpathisnull
-
simplify
Simplifies a path by retaining only every nth point based on an epsilon value.The stride is calculated as
max(1, round(1.0 / epsilon)), meaning:epsilon = 1.0→ keep every pointepsilon = 0.5→ keep every 2nd pointepsilon = 0.1→ keep every 10th point
This is a lightweight downsampling method. For geometric simplification (e.g. Ramer-Douglas-Peucker), use a dedicated algorithm.
- Parameters:
path- the path to simplifyepsilon- a value in (0.0, 1.0] controlling sampling density- Returns:
- a new simplified path
- Throws:
IllegalArgumentException- ifepsilonis not in (0.0, 1.0]
-
join
Concatenates two paths into a single continuous path.The end of the first path is connected to the start of the second. If either path is empty, the other is returned.
- Parameters:
first- the first path segmentsecond- the second path segment- Returns:
- a new path combining both
- Throws:
NullPointerException- if either argument isnull
-
trim
Truncates a path to a maximum number of positions.If the path has fewer than
maxLengthpositions, it is returned unchanged. Otherwise, only the firstmaxLengthpositions are kept.- Parameters:
path- the path to trimmaxLength- the maximum number of positions to retain- Returns:
- a new path with at most
maxLengthpositions - Throws:
IllegalArgumentException- ifmaxLength <= 0
-
mutatePositions
Applies a transformation function to every position in the path.This is a functional map operation: each
PathPositionis passed to theParameterizedSupplier, and the returned position is included in the new path.Use cases:
- Coordinate system conversion (world → screen)
- Scaling, rotation, offset
- Adding metadata (e.g. timestamp, color)
- Path animation (e.g. oscillation)
- Parameters:
path- the original pathmutator- a function that transforms one position into another- Returns:
- a new path with transformed positions
- Throws:
NullPointerException- ifmutatorisnull
-