Added Max for floating point numbers.

This commit is contained in:
Sander Schobers 2018-09-23 09:42:08 +02:00
parent 060dd4380c
commit 45e7d0c8fd
2 changed files with 29 additions and 1 deletions

22
math.go
View File

@ -17,7 +17,27 @@ func NaN() float64 {
return math.NaN()
}
// NaN32 returns not a floating point number.
// NaN32 returns not a floating point number.
func NaN32() float32 {
return float32(NaN())
}
// Max the maximum of the two values.
func Max(a, b float64) float64 {
return math.Max(a, b)
}
// Max32 the maximum of the two values.
func Max32(a, b float32) float32 {
return float32(math.Max(float64(a), float64(b)))
}
// Min the minimum of the two values.
func Min(a, b float64) float64 {
return math.Min(a, b)
}
// Min32 the minimum of the two values.
func Min32(a, b float32) float32 {
return float32(math.Min(float64(a), float64(b)))
}

View File

@ -12,3 +12,11 @@ var ZeroPtF32 = PointF32{X: 0, Y: 0}
func PtF32(x, y float32) PointF32 {
return PointF32{x, y}
}
// In tests if the point p is inside the rectangle r.
func (p PointF32) In(r RectangleF32) 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
}