2020-02-01 21:06:22 -05:00
|
|
|
package d2common
|
2020-01-26 00:39:13 -05:00
|
|
|
|
2020-06-20 00:40:49 -04:00
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
)
|
2020-01-26 00:39:13 -05:00
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// MinInt returns the minimum of the given values
|
2020-01-26 00:39:13 -05:00
|
|
|
func MinInt(a, b int) int {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// MaxInt returns the maximum of the given values
|
2020-01-26 00:39:13 -05:00
|
|
|
func MaxInt(a, b int) int {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Min returns the lower of two values
|
|
|
|
func Min(a, b uint32) uint32 {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Max returns the higher of two values
|
|
|
|
func Max(a, b uint32) uint32 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaxInt32 returns the higher of two values
|
|
|
|
func MaxInt32(a, b int32) int32 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// AbsInt32 returns the absolute of the given int32
|
2020-01-26 00:39:13 -05:00
|
|
|
func AbsInt32(a int32) int32 {
|
|
|
|
if a < 0 {
|
|
|
|
return -a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
// MinInt32 returns the higher of two values
|
|
|
|
func MinInt32(a, b int32) int32 {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
2020-07-08 09:16:56 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// BytesToInt32 converts 4 bytes to int32
|
|
|
|
|
|
|
|
// IsoToScreen converts isometric coordinates to screenspace coordinates
|
|
|
|
|
|
|
|
// ScreenToIso converts screenspace coordinates to isometric coordinates
|
|
|
|
|
2020-02-23 03:23:18 -05:00
|
|
|
// GetRadiansBetween returns the radians between two points. 0rad is facing to the right.
|
|
|
|
func GetRadiansBetween(p1X, p1Y, p2X, p2Y float64) float64 {
|
|
|
|
deltaY := p2Y - p1Y
|
|
|
|
deltaX := p2X - p1X
|
|
|
|
|
|
|
|
return math.Atan2(deltaY, deltaX)
|
|
|
|
}
|
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
// AlmostEqual returns true if two values are within threshold from each other
|
|
|
|
func AlmostEqual(a, b, threshold float64) bool {
|
|
|
|
return math.Abs(a-b) <= threshold
|
|
|
|
}
|