Documentation ¶
Overview ¶
Package d2math provides mathematical functions not included in Golang's standard math library.
The decimal numeric type used is float64.
Math also dictates the threshold for approximate equality (d2math.Epsilon). This is currently used both for moving entities and for approximate floating point equality in vector functions. See d2vector.
Index ¶
- Constants
- func Abs(a float64) float64
- func AbsInt32(a int32) int32
- func Clamp(a, min, max float64) float64
- func ClampInt(value, min, max int) int
- func CompareApprox(a, b float64) int
- func EqualsApprox(a, b float64) bool
- func GetRadiansBetween(p1X, p1Y, p2X, p2Y float64) float64
- func Lerp(a, b, x float64) float64
- func Max(a, b uint32) uint32
- func MaxInt(a, b int) int
- func MaxInt32(a, b int32) int32
- func Min(a, b uint32) uint32
- func MinInt(a, b int) int
- func MinInt32(a, b int32) int32
- func Sign(a float64) int
- func Unlerp(a, b, x float64) float64
- func WrapInt(x, max int) int
- type RangedNumber
- func (rn *RangedNumber) Add(other *RangedNumber) *RangedNumber
- func (rn RangedNumber) Clone() *RangedNumber
- func (rn *RangedNumber) Copy(other *RangedNumber) *RangedNumber
- func (rn *RangedNumber) Div(other *RangedNumber) *RangedNumber
- func (rn *RangedNumber) Equals(other *RangedNumber) bool
- func (rn *RangedNumber) Max() int
- func (rn *RangedNumber) Min() int
- func (rn *RangedNumber) Mul(other *RangedNumber) *RangedNumber
- func (rn *RangedNumber) Set(min, max int) *RangedNumber
- func (rn *RangedNumber) SetMax(max int) *RangedNumber
- func (rn *RangedNumber) SetMin(min int) *RangedNumber
- func (rn *RangedNumber) String() string
- func (rn *RangedNumber) Sub(other *RangedNumber) *RangedNumber
Constants ¶
const ( // Epsilon is used as the threshold for 'almost equal' operations. Epsilon float64 = 0.0001 // RadToDeg is used to convert anges in radians to degrees by multiplying the radians by RadToDeg. Similarly,degrees // are converted to radians when dividing by RadToDeg. RadToDeg float64 = 57.29578 // RadFull is the radian equivalent of 360 degrees. RadFull float64 = 6.283185253783088 )
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Abs returns the absolute value of a. It is a less CPU intensive version of the standard library math.Abs().
func CompareApprox ¶
CompareApprox returns an integer between -1 and 1 describing the comparison of floats a and b. 0 will be returned if the absolute difference between a and b is less than Epsilon.
func EqualsApprox ¶
EqualsApprox returns true if the difference between a and b is less than Epsilon.
func GetRadiansBetween ¶
GetRadiansBetween returns the radians between two points. 0rad is facing to the right.
Types ¶
type RangedNumber ¶
type RangedNumber struct {
// contains filtered or unexported fields
}
RangedNumber is a number with a min and max range
func (*RangedNumber) Add ¶
func (rn *RangedNumber) Add(other *RangedNumber) *RangedNumber
Add adds the given ranged number to this one, returning this one
func (RangedNumber) Clone ¶
func (rn RangedNumber) Clone() *RangedNumber
Clone creates a new copy of a ranged number, with the same min/max
func (*RangedNumber) Copy ¶
func (rn *RangedNumber) Copy(other *RangedNumber) *RangedNumber
Copy copies the min/max values of the given ranged number
func (*RangedNumber) Div ¶
func (rn *RangedNumber) Div(other *RangedNumber) *RangedNumber
Div divides this ranged number by the given ranged number, returning this one
func (*RangedNumber) Equals ¶
func (rn *RangedNumber) Equals(other *RangedNumber) bool
Equals checks equality with the given ranged number
func (*RangedNumber) Max ¶
func (rn *RangedNumber) Max() int
Max returns the max value, swapping min/max if not ordered
func (*RangedNumber) Min ¶
func (rn *RangedNumber) Min() int
Min returns the min value, swapping min/max if not ordered
func (*RangedNumber) Mul ¶
func (rn *RangedNumber) Mul(other *RangedNumber) *RangedNumber
Mul multiplies this ranged number by the given ranged number, returning this one
func (*RangedNumber) Set ¶
func (rn *RangedNumber) Set(min, max int) *RangedNumber
Set sets the min and max values, ordering the arguments if necessary
func (*RangedNumber) SetMax ¶
func (rn *RangedNumber) SetMax(max int) *RangedNumber
SetMax sets the maximum value
func (*RangedNumber) SetMin ¶
func (rn *RangedNumber) SetMin(min int) *RangedNumber
SetMin sets the minimum value
func (*RangedNumber) String ¶
func (rn *RangedNumber) String() string
func (*RangedNumber) Sub ¶
func (rn *RangedNumber) Sub(other *RangedNumber) *RangedNumber
Sub subtracts the given ranged number from this one, returning this one