PathOptimizer
This class provides utilities for optimizing paths, primarily by removing collinear points to reduce the path's complexity and size. It uses the Ramer-Douglas-Peucker (RDP) algorithm for simplification.
Methods
optimize(List<PointXY> path, double epsilon)
Optimizes a path by using the Ramer-Douglas-Peucker algorithm to remove redundant points that are approximately on a straight line.
path: The original list ofPointXYobjects representing the path.epsilon: The maximum allowed distance a point can be from a line segment before it is considered a significant corner. A smaller value results in a more detailed path; a larger value results in a more simplified path. A good starting value might be 1.0.
Returns a new List of PointXY objects representing the simplified path.
simplifyPath(List<PointXY> path, int startIndex, int endIndex, double epsilon, List<PointXY> simplifiedPath)
Private recursive helper method for the Ramer-Douglas-Peucker algorithm. It finds the point furthest from the line segment defined by startIndex and endIndex. If this distance exceeds epsilon, it recursively calls itself on the two sub-segments.
perpendicularDistance(PointXY lineStart, PointXY lineEnd, PointXY p)
Private static method. Calculates the perpendicular distance from a point (p) to a line segment defined by lineStart and lineEnd.