【发布时间】:2019-05-08 05:56:39
【问题描述】:
我遇到了this 和this 的问题,都是关于 Android 中的检测交叉点的问题。好吧,我无法让它们与最终代码一起工作,所以我做了一个例子,其中 2 行肯定相交。在那种情况下甚至没有运气。我制作了一个示例代码,其中包含两条直线路径、适合它们的区域以及一个绝对穿过它的点。完全不走运。
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
}
在此示例中,我没有使用Canvas,但在我的原始代码中,我使用了,并且每个路径都由Paint 和strokeWidth 组成。没有运气。你们中有人遇到过这种情况吗?
【问题讨论】:
标签: android kotlin android-canvas