[fixed] Path tolerance in getLength, getNearestPoint() and getPointAlongPath


#1

The path class has a tolerance setting for the PathFlatteningIterator in several methods like intersectsLine(). I need them too in getLength(), getPointAlongPath() and getNearestPoint(). Could that be added please?
I add the necessary patch, it’s straight forward…
Thanks!
Unfortunately I can’t attach a txt file with the patch, so it’s coming inline:

diff --git a/modules/juce_graphics/geometry/juce_Path.cpp b/modules/juce_graphics/geometry/juce_Path.cpp
index 7eecd66..55ad3b6 100644
--- a/modules/juce_graphics/geometry/juce_Path.cpp
+++ b/modules/juce_graphics/geometry/juce_Path.cpp
@@ -1103,10 +1103,10 @@ Line Path::getClippedLine (const Line& line, const bool keepSectio
     return result;
 }
 
-float Path::getLength (const AffineTransform& transform) const
+float Path::getLength (const AffineTransform& transform, const float tolerance) const
 {
     float length = 0;
-    PathFlatteningIterator i (*this, transform);
+    PathFlatteningIterator i (*this, transform, tolerance);
 
     while (i.next())
         length += Line (i.x1, i.y1, i.x2, i.y2).getLength();
@@ -1114,9 +1114,9 @@ float Path::getLength (const AffineTransform& transform) const
     return length;
 }
 
diff --git a/modules/juce_graphics/geometry/juce_Path.cpp b/modules/juce_graphics/geometry/juce_Path.cpp
index 7eecd66..55ad3b6 100644
--- a/modules/juce_graphics/geometry/juce_Path.cpp
+++ b/modules/juce_graphics/geometry/juce_Path.cpp
@@ -1103,10 +1103,10 @@ Line Path::getClippedLine (const Line& line, const bool keepSectio
     return result;
 }
 
-float Path::getLength (const AffineTransform& transform) const
+float Path::getLength (const AffineTransform& transform, const float tolerance) const
 {
     float length = 0;
-    PathFlatteningIterator i (*this, transform);
+    PathFlatteningIterator i (*this, transform, tolerance);
 
     while (i.next())
         length += Line (i.x1, i.y1, i.x2, i.y2).getLength();
@@ -1114,9 +1114,9 @@ float Path::getLength (const AffineTransform& transform) const
     return length;
 }
 
-Point Path::getPointAlongPath (float distanceFromStart, const AffineTransform& transform) const
+Point Path::getPointAlongPath (float distanceFromStart, const AffineTransform& transform, const float tolerance) const
 {
-    PathFlatteningIterator i (*this, transform);
+    PathFlatteningIterator i (*this, transform, tolerance);
 
     while (i.next())
     {
@@ -1133,9 +1133,9 @@ Point Path::getPointAlongPath (float distanceFromStart, const AffineTrans
 }
 
 float Path::getNearestPoint (const Point targetPoint, Point& pointOnPath,
-                             const AffineTransform& transform) const
+                             const AffineTransform& transform, const float tolerance) const
 {
-    PathFlatteningIterator i (*this, transform);
+    PathFlatteningIterator i (*this, transform, tolerance);
     float bestPosition = 0, bestDistance = std::numeric_limits::max();
     float length = 0;
     Point pointOnLine;
diff --git a/modules/juce_graphics/geometry/juce_Path.h b/modules/juce_graphics/geometry/juce_Path.h
index 215314f..4d0e1f7 100644
--- a/modules/juce_graphics/geometry/juce_Path.h
+++ b/modules/juce_graphics/geometry/juce_Path.h
@@ -158,7 +158,8 @@ public:
     /** Returns the length of the path.
         @see getPointAlongPath
     */
-    float getLength (const AffineTransform& transform = AffineTransform()) const;
+    float getLength (const AffineTransform& transform = AffineTransform(),
+                     const float tolerance = 0.6f) const;
 
     /** Returns a point that is the specified distance along the path.
         If the distance is greater than the total length of the path, this will return the
@@ -166,7 +167,8 @@ public:
         @see getLength
     */
     Point getPointAlongPath (float distanceFromStart,
-                                    const AffineTransform& transform = AffineTransform()) const;
+                                    const AffineTransform& transform = AffineTransform(),
+                                    const float tolerance = 0.6f) const;
 
     /** Finds the point along the path which is nearest to a given position.
         This sets pointOnPath to the nearest point, and returns the distance of this point from the start
@@ -174,7 +176,8 @@ public:
     */
     float getNearestPoint (const Point targetPoint,
                            Point& pointOnPath,
-                           const AffineTransform& transform = AffineTransform()) const;
+                           const AffineTransform& transform = AffineTransform(),
+                           const float tolerance = 0.6f) const;
 
     //==============================================================================
     /** Removes all lines and curves, resetting the path completely. */



#2

Thanks, good request, will add that when I get a moment…


#3

Great, many thanks…