我有一个 image.Point
和一个 image.Rectangle
。我想知道如何检查点是否在矩形中。我知道我可以手动检查:
p := image.Point{}
r := image.Rect{}
if r.Min.X <= p.X && p.X < r.Max.X && r.Min.Y <= p.Y && p.Y < r.Max.Y {
// Point is in the rectangle!
}
但这很痛苦!有一个更好的方法吗?我在 documentation 中找不到 Contains()
.
最佳答案
if p.In(r) {
…
}
关于go - 检查点是否在矩形中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32019777/