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

#1

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;
}
0 Likes