I came across this and this questions, all about detection intersections in Android. Well, I couldn't manage to make them work with the final code, so I made an example where 2 lines definitely intersect. Not even lucky in that case. I've made an example code with two straight paths, regions that fit them, and a point that definitely crosses it. Completely unlucky.
var theyCross = false
val intersectionPath = Path()
val clipArea = Region(0, 0, 100, 100)
val path1 = Path()
path1.moveTo(50f, 0f)
path1.lineTo(50f, 100f)
val path2 = Path()
path2.moveTo(0f, 50f)
path2.lineTo(100f, 50f)
val newRegion1 = Region()
newRegion1.setPath(path1, clipArea)
val newRegion2 = Region()
newRegion2.setPath(path2, clipArea)
if(
!newRegion1.quickReject(newRegion2) &&
newRegion1.op(newRegion2, Region.Op.INTERSECT)
) {
// lines should cross!
theyCross = true
}
if (intersectionPath.op(path1, path2, Path.Op.INTERSECT)) {
if (!intersectionPath.isEmpty) {
// lines should cross!
theyCross = true
}
}
if (newRegion1.contains(50, 50)) {
// lines should cross!
theyCross = true
}
if (newRegion1.quickContains(49, 49, 51, 51)) {
// lines should cross!
theyCross = true
}
In this example I'm not using a Canvas
, but in my original code, I am, and each path is made of a Paint
with strokeWidth
. No luck. Has any of you faced this before?