mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added some extra tolerance settings to some Path methods
This commit is contained in:
parent
0a0c550198
commit
9abd4eeace
5 changed files with 33 additions and 27 deletions
|
|
@ -60,6 +60,9 @@ const float Path::quadMarker = 100003.0f;
|
|||
const float Path::cubicMarker = 100004.0f;
|
||||
const float Path::closeSubPathMarker = 100005.0f;
|
||||
|
||||
const float Path::defaultToleranceForTesting = 1.0f;
|
||||
const float Path::defaultToleranceForMeasurement = 0.6f;
|
||||
|
||||
//==============================================================================
|
||||
Path::PathBounds::PathBounds() noexcept
|
||||
: pathXMin (0), pathXMax (0), pathYMin (0), pathYMax (0)
|
||||
|
|
@ -1060,7 +1063,7 @@ bool Path::contains (const Point<float> point, const float tolerance) const
|
|||
return contains (point.x, point.y, tolerance);
|
||||
}
|
||||
|
||||
bool Path::intersectsLine (const Line<float>& line, const float tolerance)
|
||||
bool Path::intersectsLine (Line<float> line, const float tolerance)
|
||||
{
|
||||
PathFlatteningIterator i (*this, AffineTransform(), tolerance);
|
||||
Point<float> intersection;
|
||||
|
|
@ -1072,7 +1075,7 @@ bool Path::intersectsLine (const Line<float>& line, const float tolerance)
|
|||
return false;
|
||||
}
|
||||
|
||||
Line<float> Path::getClippedLine (const Line<float>& line, const bool keepSectionOutsidePath) const
|
||||
Line<float> Path::getClippedLine (Line<float> line, const bool keepSectionOutsidePath) const
|
||||
{
|
||||
Line<float> result (line);
|
||||
const bool startInside = contains (line.getStart());
|
||||
|
|
@ -1103,10 +1106,10 @@ Line<float> Path::getClippedLine (const Line<float>& line, const bool keepSectio
|
|||
return result;
|
||||
}
|
||||
|
||||
float Path::getLength (const AffineTransform& transform) const
|
||||
float Path::getLength (const AffineTransform& transform, float tolerance) const
|
||||
{
|
||||
float length = 0;
|
||||
PathFlatteningIterator i (*this, transform);
|
||||
PathFlatteningIterator i (*this, transform, tolerance);
|
||||
|
||||
while (i.next())
|
||||
length += Line<float> (i.x1, i.y1, i.x2, i.y2).getLength();
|
||||
|
|
@ -1114,9 +1117,11 @@ float Path::getLength (const AffineTransform& transform) const
|
|||
return length;
|
||||
}
|
||||
|
||||
Point<float> Path::getPointAlongPath (float distanceFromStart, const AffineTransform& transform) const
|
||||
Point<float> Path::getPointAlongPath (float distanceFromStart,
|
||||
const AffineTransform& transform,
|
||||
float tolerance) const
|
||||
{
|
||||
PathFlatteningIterator i (*this, transform);
|
||||
PathFlatteningIterator i (*this, transform, tolerance);
|
||||
|
||||
while (i.next())
|
||||
{
|
||||
|
|
@ -1133,9 +1138,10 @@ Point<float> Path::getPointAlongPath (float distanceFromStart, const AffineTrans
|
|||
}
|
||||
|
||||
float Path::getNearestPoint (const Point<float> targetPoint, Point<float>& pointOnPath,
|
||||
const AffineTransform& transform) const
|
||||
const AffineTransform& transform,
|
||||
float tolerance) const
|
||||
{
|
||||
PathFlatteningIterator i (*this, transform);
|
||||
PathFlatteningIterator i (*this, transform, tolerance);
|
||||
float bestPosition = 0, bestDistance = std::numeric_limits<float>::max();
|
||||
float length = 0;
|
||||
Point<float> pointOnLine;
|
||||
|
|
|
|||
|
|
@ -83,12 +83,14 @@ public:
|
|||
bool operator== (const Path&) const noexcept;
|
||||
bool operator!= (const Path&) const noexcept;
|
||||
|
||||
static const float defaultToleranceForTesting;
|
||||
static const float defaultToleranceForMeasurement;
|
||||
|
||||
//==============================================================================
|
||||
/** Returns true if the path doesn't contain any lines or curves. */
|
||||
bool isEmpty() const noexcept;
|
||||
|
||||
/** Returns the smallest rectangle that contains all points within the path.
|
||||
*/
|
||||
/** Returns the smallest rectangle that contains all points within the path. */
|
||||
Rectangle<float> getBounds() const noexcept;
|
||||
|
||||
/** Returns the smallest rectangle that contains all points within the path
|
||||
|
|
@ -110,7 +112,7 @@ public:
|
|||
@see closeSubPath, setUsingNonZeroWinding
|
||||
*/
|
||||
bool contains (float x, float y,
|
||||
float tolerance = 1.0f) const;
|
||||
float tolerance = defaultToleranceForTesting) const;
|
||||
|
||||
/** Checks whether a point lies within the path.
|
||||
|
||||
|
|
@ -126,7 +128,7 @@ public:
|
|||
@see closeSubPath, setUsingNonZeroWinding
|
||||
*/
|
||||
bool contains (const Point<float> point,
|
||||
float tolerance = 1.0f) const;
|
||||
float tolerance = defaultToleranceForTesting) const;
|
||||
|
||||
/** Checks whether a line crosses the path.
|
||||
|
||||
|
|
@ -138,8 +140,8 @@ public:
|
|||
so this method could return a false positive when your point is up to this distance
|
||||
outside the path's boundary.
|
||||
*/
|
||||
bool intersectsLine (const Line<float>& line,
|
||||
float tolerance = 1.0f);
|
||||
bool intersectsLine (Line<float> line,
|
||||
float tolerance = defaultToleranceForTesting);
|
||||
|
||||
/** Cuts off parts of a line to keep the parts that are either inside or
|
||||
outside this path.
|
||||
|
|
@ -153,12 +155,13 @@ public:
|
|||
that will be kept; if false its the section inside
|
||||
the path
|
||||
*/
|
||||
Line<float> getClippedLine (const Line<float>& line, bool keepSectionOutsidePath) const;
|
||||
Line<float> getClippedLine (Line<float> line, bool keepSectionOutsidePath) const;
|
||||
|
||||
/** Returns the length of the path.
|
||||
@see getPointAlongPath
|
||||
*/
|
||||
float getLength (const AffineTransform& transform = AffineTransform()) const;
|
||||
float getLength (const AffineTransform& transform = AffineTransform(),
|
||||
float tolerance = defaultToleranceForMeasurement) 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,15 +169,17 @@ public:
|
|||
@see getLength
|
||||
*/
|
||||
Point<float> getPointAlongPath (float distanceFromStart,
|
||||
const AffineTransform& transform = AffineTransform()) const;
|
||||
const AffineTransform& transform = AffineTransform(),
|
||||
float tolerance = defaultToleranceForMeasurement) 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
|
||||
of the path.
|
||||
*/
|
||||
float getNearestPoint (const Point<float> targetPoint,
|
||||
float getNearestPoint (Point<float> targetPoint,
|
||||
Point<float>& pointOnPath,
|
||||
const AffineTransform& transform = AffineTransform()) const;
|
||||
const AffineTransform& transform = AffineTransform(),
|
||||
float tolerance = defaultToleranceForMeasurement) const;
|
||||
|
||||
//==============================================================================
|
||||
/** Removes all lines and curves, resetting the path completely. */
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@
|
|||
#pragma optimize ("t", on)
|
||||
#endif
|
||||
|
||||
const float PathFlatteningIterator::defaultTolerance = 0.6f;
|
||||
|
||||
//==============================================================================
|
||||
PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
|
||||
const AffineTransform& transform_,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public:
|
|||
*/
|
||||
PathFlatteningIterator (const Path& path,
|
||||
const AffineTransform& transform = AffineTransform(),
|
||||
float tolerance = defaultTolerance);
|
||||
float tolerance = Path::defaultToleranceForMeasurement);
|
||||
|
||||
/** Destructor. */
|
||||
~PathFlatteningIterator();
|
||||
|
|
@ -90,9 +90,6 @@ public:
|
|||
/** Returns true if the current segment is the last in the current sub-path. */
|
||||
bool isLastInSubpath() const noexcept;
|
||||
|
||||
/** This is the default value that should be used for the tolerance value (see the constructor parameters). */
|
||||
static const float defaultTolerance;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
const Path& path;
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ namespace PathStrokeHelpers
|
|||
|
||||
// Iterate the path, creating a list of the
|
||||
// left/right-hand lines along either side of it...
|
||||
PathFlatteningIterator it (*sourcePath, transform, PathFlatteningIterator::defaultTolerance / extraAccuracy);
|
||||
PathFlatteningIterator it (*sourcePath, transform, Path::defaultToleranceForMeasurement / extraAccuracy);
|
||||
|
||||
Array <LineSection> subPath;
|
||||
subPath.ensureStorageAllocated (512);
|
||||
|
|
@ -668,7 +668,7 @@ void PathStrokeType::createDashedStroke (Path& destPath,
|
|||
return;
|
||||
|
||||
Path newDestPath;
|
||||
PathFlatteningIterator it (sourcePath, transform, PathFlatteningIterator::defaultTolerance / extraAccuracy);
|
||||
PathFlatteningIterator it (sourcePath, transform, Path::defaultToleranceForMeasurement / extraAccuracy);
|
||||
|
||||
bool first = true;
|
||||
int dashNum = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue