From 9b12441b4320131724954e516300543e53ee4a0f Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 28 Dec 2019 18:26:08 +0100 Subject: [PATCH] Added {Min,Max}Pt{,F,F32}. --- point.go | 10 ++++++++++ pointf.go | 10 ++++++++++ pointf32.go | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/point.go b/point.go index bd5c54d..a88a43f 100644 --- a/point.go +++ b/point.go @@ -108,6 +108,11 @@ func (p Point) ToF() PointF { return PtF(float64(p.X), float64(p.Y)) } // ToF32 returns the floating point representation of p. func (p Point) ToF32() PointF32 { return PtF32(float32(p.X), float32(p.Y)) } +// MaxPt returns the point that is at the largest X & Y position of a and b. +func MaxPt(a, b Point) Point { + return Pt(ints.Max(a.X, b.X), ints.Max(a.Y, b.Y)) +} + // MinMaxPoints returns the extremes of all the given points. func MinMaxPoints(p ...Point) (min Point, max Point) { if 0 == len(p) { @@ -129,3 +134,8 @@ func MinMaxPoints(p ...Point) (min Point, max Point) { } return min, max } + +// MinPt returns the point that is at the smallest X & Y position of a and b. +func MinPt(a, b Point) Point { + return Pt(ints.Min(a.X, b.X), ints.Min(a.Y, b.Y)) +} diff --git a/pointf.go b/pointf.go index c7f3d16..3808e65 100644 --- a/pointf.go +++ b/pointf.go @@ -146,3 +146,13 @@ func (p PointF) Sub(q PointF) PointF { func (p PointF) To32() PointF32 { return PointF32{float32(p.X), float32(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)) +} + +// MinPtF returns the point that is at the smallest X & Y position of a and b. +func MinPtF(a, b PointF) PointF { + return PtF(Min(a.X, b.X), Min(a.Y, b.Y)) +} diff --git a/pointf32.go b/pointf32.go index a0a986c..2f40260 100644 --- a/pointf32.go +++ b/pointf32.go @@ -146,3 +146,13 @@ func (p PointF32) Sub(q PointF32) PointF32 { func (p PointF32) To64() PointF { return PointF{float64(p.X), float64(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)) +} + +// MinPtF32 returns the point that is at the smallest X & Y position of a and b. +func MinPtF32(a, b PointF32) PointF32 { + return PtF32(Min32(a.X, b.X), Min32(a.Y, b.Y)) +}