How can we check that point is inside a path? I sa...
# compose-desktop
r
How can we check that point is inside a path? I saw two functions in android
Path.op(path2: Path, op: Op)
and
Path.op(path1: Path, path2: Path, op: Op)
But in compose there is only one
Path.op(path1: Path, path2: Path, op: Op)
d
How do you use Path.op to check if a pointer is inside a path? Looking at the docs it seems unrelated. Here's what I'm currently doing on android, and I'm wondering if what you're describing would work better.
Copy code
fun Path.contains(offset: IntOffset): Boolean {
    // See <<https://stackoverflow.com/a/10586689>>
    val path = asAndroidPath()
    val bounds = RectF()
    path.computeBounds(bounds, true)
    val region = Region().apply {
        setPath(path, bounds.toRegion())
    }

    return region.contains(offset.x, offset.y)
}
r
The region is android specific isn’t it?
d
Totally, this wouldn't solve your question at all. I just saw your post and wondered if I was missing something I could use in my own android app
r
I’m also wondering if there is any built-in method . I tried all param options but the result is same
Copy code
val path = Path()
val success = path.op(path1, path2, PathOperation.intersect)
drawPath(path, Color.Black)
d
Doesn't the code you've posted compute the intersection of two paths instead of checking if a point is inside a pth?
r
If there is no intersection it means the point is not inside the path. Am I wrong?
d
Are you allowed to create a path that's just a single point?
r
We can draw circle with minimum radius
d
And that works on Android?
r
I tried it with compose path. It didn’t work. Now I’m trying it with android path
d
Because I wouldn't be surprised if Float.MIN_VALUE sized circles behave weirdly
r
The android path works
d
Thanks
Good luck!
r
It is drawing only intersection
But compose path is rendering only union path