Added PointF{,32}.ToInt that converts the point to a Point.

Added Point.In(Rectangle).
This commit is contained in:
Sander Schobers 2020-05-16 19:52:05 +02:00
parent 17af2eb843
commit 18bac571b8
3 changed files with 18 additions and 0 deletions

View File

@ -64,6 +64,14 @@ func (p Point) DistInt(q Point) int {
return ints.SubAbs(p.X, q.X) + ints.SubAbs(p.Y, q.Y)
}
// In tests if the point p is inside the rectangle r.
func (p Point) In(r Rectangle) bool {
if p.X < r.Min.X || p.X >= r.Max.X || p.Y < r.Min.Y || p.Y >= r.Max.Y {
return false
}
return true
}
// Less returns true if q is above (Y is smaller) or left (X is smaller) than p. Otherwise returns false.
func (p Point) Less(q Point) bool {
if p.Y == q.Y {

View File

@ -147,6 +147,11 @@ func (p PointF) To32() PointF32 {
return PointF32{float32(p.X), float32(p.Y)}
}
// ToInt transforms the point p into a Point.
func (p PointF) ToInt() Point {
return Point{int(p.X), int(p.Y)}
}
// MaxPtF returns the point that is at the largest X & Y position of a and b.
func MaxPtF(a, b PointF) PointF {
return PtF(Max(a.X, b.X), Max(a.Y, b.Y))

View File

@ -147,6 +147,11 @@ func (p PointF32) To64() PointF {
return PointF{float64(p.X), float64(p.Y)}
}
// ToInt transforms the point p into a Point.
func (p PointF32) ToInt() Point {
return Point{int(p.X), int(p.Y)}
}
// MaxPtF32 returns the point that is at the largest X & Y position of a and b.
func MaxPtF32(a, b PointF32) PointF32 {
return PtF32(Max32(a.X, b.X), Max32(a.Y, b.Y))