Is there a way to see if a rectangle or line or other path intersects a closed, stroked path?
i’m running into this problem trying to fit a rectangle inside a path created with a roundedRect inside it and drawing using g.strokePath().
here’s my algorithm for finding the inside bounds, which is kind of brute-force-ish.
Rectangle<float> innerBoundingBox = borderOutline.getBounds().toFloat().reduced(1.0f); //slightly inside our path
while( true ) {
Line<float> leftEdge(innerBoundingBox.getTopLeft(), innerBoundingBox.getBottomLeft());
Line<float> topEdge(innerBoundingBox.getTopLeft(), innerBoundingBox.getTopRight());
if( !borderOutline.intersectsLine(leftEdge) && !borderOutline.intersectsLine(topEdge) ) {
break;
}
innerBoundingBox.reduce(1, 1);
}
here’s what result i’m hoping to achieve all the time, where the red rectangle is entirely inside the path
here’s what happens some of the time:
here’s a 16 second clip of it in action and the flaws of the algorithm.
Basically, can we get a Path::strokedPathIntersectsLine() method?