Added {Min,Max}Pt{,F,F32}.

This commit is contained in:
Sander Schobers 2019-12-28 18:26:08 +01:00
parent ac8c2029e4
commit 9b12441b43
3 changed files with 30 additions and 0 deletions

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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))
}