I think I unveiled a flaw in RPolyline::getDistancesFromStart(p)
For a point near a line segment it uses RLine::getDistanceFromStart(p)
For both it is not stated but I suspect that especially the RLine method assumes that the point is on the shape.
While the RPolyline method intentionally allows a point to be within 0.0001 from any segment for some unknown purpose.
Assumed to be a fix for general cases that don't require more than a 3-4 digits accuracy.
Code: Select all
if (segment->getDistanceTo(p)<0.0001) {.. add partial length ..}Code: Select all
double ret = startPoint.getDistanceTo(p);In essence the hypotenuse of the triangle: start - point p - projection of p on the unlimited line shape.
Because the distance point p - projection is not larger than 0.0001 here ...
... The differences are small but there are some peculiarities.
When point p is a little in front of the first RLine (P4), a positive value is returned meaning that it is beyond the start and on the shape.
In front in any direction because getVectorTo() in limited mode returns a direct vector towards the nearest endpoint.
Same happens beyond the segment (P3) adding more than the segment length as partial length.
meaning that it is beyond the end of the segment and thus on the next segment.
A second distance for the next segment can even be shorter than the former.
e.g. [72.11106081405715 , 72.11092560927979] expecting 72.11102550927978 or the corner vertex.
Visualized it looks like this:
Green are the 0.0001 tolerance areas, exaggerated.
The accounted for partial distance ? along ? the polyline segment are the yellow dotted lines for each points that is near enough.
P2, P3 and P5 are considered to be near both segments.
Also, there are several other pitfalls for this RPolyline method.
Mostly concerning bulging or Arc-like segments or a mix of.
Regards,
CVH