Bladeren bron

Using github.com/chewxy/math32 module

Min 1 jaar geleden
bovenliggende
commit
4f0267c445
3 gewijzigde bestanden met toevoegingen van 48 en 23 verwijderingen
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 45 23
      math32/math.go

+ 1 - 0
go.mod

@@ -3,6 +3,7 @@ module github.com/g3n/engine
 go 1.13
 
 require (
+	github.com/chewxy/math32 v1.10.1
 	github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb
 	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
 	golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9

+ 2 - 0
go.sum

@@ -1,3 +1,5 @@
+github.com/chewxy/math32 v1.10.1 h1:LFpeY0SLJXeaiej/eIp2L40VYfscTvKh/FSEZ68uMkU=
+github.com/chewxy/math32 v1.10.1/go.mod h1:dOB2rcuFrCn6UHrze36WSLVPKtzPMRAQvBvUwkSsLqs=
 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=

+ 45 - 23
math32/math.go

@@ -9,14 +9,14 @@
 package math32
 
 import (
-	"math"
+	m32 "github.com/chewxy/math32"
 )
 
-const Pi = math.Pi
-const degreeToRadiansFactor = math.Pi / 180
-const radianToDegreesFactor = 180.0 / math.Pi
+const Pi = m32.Pi
+const degreeToRadiansFactor = m32.Pi / 180
+const radianToDegreesFactor = 180.0 / m32.Pi
 
-var Infinity = float32(math.Inf(1))
+var Infinity = m32.Inf(1)
 
 // DegToRad converts a number from degrees to radians
 func DegToRad(degrees float32) float32 {
@@ -55,39 +55,39 @@ func ClampInt(x, a, b int) int {
 }
 
 func Abs(v float32) float32 {
-	return float32(math.Abs(float64(v)))
+	return m32.Abs(v)
 }
 
 func Acos(v float32) float32 {
-	return float32(math.Acos(float64(v)))
+	return m32.Acos(v)
 }
 
 func Asin(v float32) float32 {
-	return float32(math.Asin(float64(v)))
+	return m32.Asin(v)
 }
 
 func Atan(v float32) float32 {
-	return float32(math.Atan(float64(v)))
+	return m32.Atan(v)
 }
 
 func Atan2(y, x float32) float32 {
-	return float32(math.Atan2(float64(y), float64(x)))
+	return m32.Atan2(y, x)
 }
 
 func Ceil(v float32) float32 {
-	return float32(math.Ceil(float64(v)))
+	return m32.Ceil(v)
 }
 
 func Cos(v float32) float32 {
-	return float32(math.Cos(float64(v)))
+	return m32.Cos(v)
 }
 
 func Floor(v float32) float32 {
-	return float32(math.Floor(float64(v)))
+	return m32.Floor(v)
 }
 
 func Inf(sign int) float32 {
-	return float32(math.Inf(sign))
+	return m32.Inf(sign)
 }
 
 func Round(v float32) float32 {
@@ -95,37 +95,59 @@ func Round(v float32) float32 {
 }
 
 func IsNaN(v float32) bool {
-	return math.IsNaN(float64(v))
+	return m32.IsNaN(v)
 }
 
 func Sin(v float32) float32 {
-	return float32(math.Sin(float64(v)))
+	return m32.Sin(v)
 }
 
 func Sqrt(v float32) float32 {
-	return float32(math.Sqrt(float64(v)))
+	return m32.Sqrt(v)
+}
+
+func Log(v float32) float32 {
+	return m32.Log(v)
+}
+
+func Exp(v float32) float32 {
+	return m32.Exp(v)
 }
 
 func Max(a, b float32) float32 {
-	return float32(math.Max(float64(a), float64(b)))
+	return m32.Max(a, b)
 }
 
 func Min(a, b float32) float32 {
-	return float32(math.Min(float64(a), float64(b)))
+	return m32.Min(a, b)
+}
+
+func MaxInt(a, b int) int {
+	if a > b {
+		return a
+	}
+	return b
+}
+
+func MinInt(a, b int) int {
+	if a < b {
+		return a
+	}
+	return b
 }
 
 func Mod(a, b float32) float32 {
-	return float32(math.Mod(float64(a), float64(b)))
+	return m32.Mod(a, b)
 }
 
 func NaN() float32 {
-	return float32(math.NaN())
+	return m32.NaN()
 }
 
 func Pow(a, b float32) float32 {
-	return float32(math.Pow(float64(a), float64(b)))
+	return m32.Pow(a, b)
 }
 
 func Tan(v float32) float32 {
-	return float32(math.Tan(float64(v)))
+	return m32.Tan(v)
 }