2019-11-10 03:36:53 -05:00
|
|
|
package d2helper
|
2019-10-24 09:31:59 -04:00
|
|
|
|
|
|
|
// Min returns the lower of two values
|
|
|
|
func Min(a, b uint32) uint32 {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Max returns the higher of two values
|
|
|
|
func Max(a, b uint32) uint32 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2019-10-25 19:12:42 -04:00
|
|
|
// MaxInt32 returns the higher of two values
|
2019-10-24 09:31:59 -04:00
|
|
|
func MaxInt32(a, b int32) int32 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:12:07 -04:00
|
|
|
func NextPow2(x int32) int32 {
|
|
|
|
result := int32(1)
|
|
|
|
for result < x {
|
|
|
|
result *= 2
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-11-01 14:12:23 -04:00
|
|
|
func AbsInt32(a int32) int32 {
|
|
|
|
if a < 0 {
|
|
|
|
return -a
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2019-10-26 20:09:33 -04:00
|
|
|
// MinInt32 returns the higher of two values
|
|
|
|
func MinInt32(a, b int32) int32 {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:31:59 -04:00
|
|
|
// BytesToInt32 converts 4 bytes to int32
|
|
|
|
func BytesToInt32(b []byte) int32 {
|
|
|
|
// equivalnt of return int32(binary.LittleEndian.Uint32(b))
|
|
|
|
return int32(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
|
|
|
|
}
|
2019-11-01 22:41:49 -04:00
|
|
|
|
|
|
|
func IsoToScreen(isoX, isoY, modX, modY int) (int, int) {
|
|
|
|
screenX := (isoX - isoY) * 80
|
|
|
|
screenY := (isoX + isoY) * 40
|
|
|
|
return screenX + modX, screenY + modY
|
|
|
|
}
|
2019-11-06 18:25:19 -05:00
|
|
|
|
|
|
|
func ScreenToIso(sx, sy float64) (float64, float64) {
|
|
|
|
x := (sx/80 + sy/40) / 2
|
|
|
|
y := (sy/40 - (sx / 80)) / 2
|
|
|
|
return x, y
|
|
|
|
}
|