Path hittest

62 views
Skip to first unread message

aiz berg

unread,
Apr 18, 2025, 4:19:10 PM4/18/25
to skia-discuss
is it possible to somehow check if path intersects with rect? There are pathops that return the final path of intersection, and not just a bool flag, and they work quite slowly in some cases. However, path has a contains method that works very quickly for a specific point, maybe there is some analog for rect?

Mike Reed

unread,
May 2, 2025, 3:52:56 PM5/2/25
to skia-d...@googlegroups.com
Such a utility is doable, but Skia doesn't have it (afaik)

A little slower, but you can do this via a tiny draw...
1. create a tiny raster canvas the dimensions of your rect
2. translate the canvas by the negative of your rects left, top
3. draw the path into that canvas (with any opaque color)
4. read the pixels in the canvas -- if any of them are not transparent -- the path intersected the rect

Depending, you may or may not want to enable AA on the paint when you draw

On Fri, Apr 18, 2025 at 4:19 PM aiz berg <bakug...@gmail.com> wrote:
is it possible to somehow check if path intersects with rect? There are pathops that return the final path of intersection, and not just a bool flag, and they work quite slowly in some cases. However, path has a contains method that works very quickly for a specific point, maybe there is some analog for rect?

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skia-discuss/9c0a9efb-1ad4-4dfe-be01-05d070afda7an%40googlegroups.com.


--
"I think I can safely say that nobody understands quantum mechanics." -- Richard Feynman
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so." -- Mark Twain
"I am pleased to see that we have differences" -- Surak

Reply all
Reply to author
Forward
0 new messages