diff --git a/point.go b/point.go index a88a43f..965f86a 100644 --- a/point.go +++ b/point.go @@ -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 { diff --git a/pointf.go b/pointf.go index 3808e65..0a8d206 100644 --- a/pointf.go +++ b/pointf.go @@ -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)) diff --git a/pointf32.go b/pointf32.go index 2f40260..7777961 100644 --- a/pointf32.go +++ b/pointf32.go @@ -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))