Split out maths functions into maths, vector and bearing
This commit is contained in:
parent
aae668fb57
commit
51fe918090
14 changed files with 335 additions and 273 deletions
pkg/maths
41
pkg/maths/maths.go
Normal file
41
pkg/maths/maths.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package maths
|
||||
|
||||
// Abs gets the absolute value of an int
|
||||
func Abs(x int) int {
|
||||
if x < 0 {
|
||||
return -x
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// pmod is a mositive modulo
|
||||
// golang's % is a "remainder" function si misbehaves for negative modulus inputs
|
||||
func Pmod(x, d int) int {
|
||||
if x == 0 || d == 0 {
|
||||
return 0
|
||||
}
|
||||
x = x % d
|
||||
if x >= 0 {
|
||||
return x
|
||||
} else if d < 0 {
|
||||
return x - d
|
||||
} else {
|
||||
return x + d
|
||||
}
|
||||
}
|
||||
|
||||
// Max returns the highest int
|
||||
func Max(x int, y int) int {
|
||||
if x < y {
|
||||
return y
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// Min returns the lowest int
|
||||
func Min(x int, y int) int {
|
||||
if x > y {
|
||||
return y
|
||||
}
|
||||
return x
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue