Check if point is in rectangle

时间:2015-08-14 22:59:32

标签: go

I have an image.Point and an image.Rectangle. I'd like to know how to check if the point is in the rectangle. I know that I can manually check with:

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!
}

But that is a pain! Is there a better way to do this? I can't find a Contains() in the documentation.

0 个答案:

没有答案