Path::intersectsLine(Line<float> line, float tolerance, Point<float>& intersection)

instead of having that intersection variable be in the function, if it was passed into the function, we wouldn’t need to copy this function to get the intersection point of a line with our path.,

bool Path::intersectsLine (Line<float> line, float tolerance)
{
    PathFlatteningIterator i (*this, AffineTransform(), tolerance);
    Point<float> intersection;

    while (i.next())
        if (line.intersects (Line<float> (i.x1, i.y1, i.x2, i.y2), intersection))
            return true;

    return false;
}

Here’s a free function variant that provides some intersection points:

bool intersectsPath(const Path &p, Line<float> line, Array<Point<float>> &possibleIntersections)
{
    PathFlatteningIterator i (p, AffineTransform(), Path::defaultToleranceForTesting);

    Point<float> intersectionPoint;
    while (i.next())
    {
        if (line.intersects (Line<float> (i.x1, i.y1, i.x2, i.y2), intersectionPoint))
        {
            possibleIntersections.add( intersectionPoint );
        }
    }

    if( possibleIntersections.isEmpty() )
        return false;

    return true;
}

Very nice method, thanks. I used it in my code, of course in my code I added link to this post :slight_smile:

At all it was very strange for me that there is not such method in juce library. I mean method that returns Point<ValueType> of line and path which intersects together.

If the size of the possibleIntersections was 0, you’d know that the interceptsLine function will have returned false… so you could just return the Array rather than having an output parameter.

Then this is simply getPointsOfIntersectionWithLine.