Documentation
¶
Overview ¶
Package blmath contains numeric and math related functions.
Index ¶
- Constants
- func Abs[T Number](num T) T
- func Clamp(value float64, min float64, max float64) float64
- func ComplexImagAbs(z complex128) complex128
- func ComplexMagnitude(z complex128) float64
- func CosRange(angle float64, min float64, max float64) float64
- func DegToRad(d float64) float64
- func Difference(a, b float64) float64
- func DigRoot(value int) int
- func Equalish(a float64, b float64, delta float64) bool
- func Fract(n float64) float64
- func GCD(a, b int) int
- func Gamma(val, gamma float64) float64
- func LCM(x, y int) int
- func Lerp(t float64, min float64, max float64) float64
- func LoopCos(t, min, max float64) float64
- func LoopSin(t, min, max float64) float64
- func LoopSquare(t, min, max float64) float64
- func LoopTri(t, min, max float64) float64
- func Map(srcValue float64, srcMin float64, srcMax float64, dstMin float64, ...) float64
- func MapExpLin(srcValue, srcMin, srcMax, dstMin, dstMax float64) float64
- func MapFloats(list []float64, minVal, maxVal float64) []float64
- func MapLinExp(srcValue, srcMin, srcMax, dstMin, dstMax float64) float64
- func Max[T Number](a, b T) T
- func Min[T Number](a, b T) T
- func MinMaxFloats(list []float64) (float64, float64)
- func ModPos(a, b float64) float64
- func ModPosInt(a, b int) int
- func Norm(value float64, min float64, max float64) float64
- func NormalizeFloats(list []float64) []float64
- func Quantize(val, min, max float64, steps int) float64
- func RadToDeg(r float64) float64
- func RoundTo(value float64, decimal int) float64
- func RoundToNearest(value float64, mult float64) float64
- func Simplify(x, y int) (int, int)
- func SinRange(angle float64, min float64, max float64) float64
- func Wrap(value float64, min float64, max float64) float64
- func WrapPi(value float64) float64
- func WrapTau(value float64) float64
- type Number
Constants ¶
const HalfPi = math.Pi / 2
HalfPi pi / 2
const Tau = math.Pi * 2
Tau 2 pi
const TwoPi = math.Pi * 2
TwoPi 2 pi
Variables ¶
This section is empty.
Functions ¶
func ComplexImagAbs ¶
func ComplexImagAbs(z complex128) complex128
ComplexImagAbs returns a complex number with the real component and the abolute value of the imaginary component. Useful for certain types of fractals, such as "duck fractals"
func ComplexMagnitude ¶
func ComplexMagnitude(z complex128) float64
ComplexMagnitude returns the magnitude of a complex number
func Difference ¶
Difference returns the absolute value of the difference between two numbers.
func DigRoot ¶
DigRoot returns the digital root of a number, which is the sum of the numbers digits, repeated until it yields a single digit.
func Gamma ¶
Gamma increases/decreases the given value by an amount specified in gamma. Usually val is a pixel brightness value from 0.0 - 1.0. gamma of 1.0 makes no change. Higher is brighter, lower is darker.
func LoopCos ¶
LoopCos is the same as LoopSin but out of phase. In this version the values will go from the mid point, to max to min and back to mid as t goes from 0 to 1. Yes, yes, LoopSin uses cos, and LoopCos uses sin. Deal with it.
func LoopSin ¶
LoopSin maps a normal value to min and max values with a sine wave. In this version the values will go from min, to max and back as t goes from 0 to 1.
func LoopSquare ¶
LoopSquare maps a normal value to min and max values. It alternates between the min and max, max for the first part of the cycle, then min.
func LoopTri ¶
LoopTri maps a normal value to min and max values linearly. In this version the values will go from min, to max and back as t goes from 0 to 1. Similar to LoopSin, but moves at a constant speed.
func MapExpLin ¶
MapExpLin maps a value within an exponential min/max range to another linear range. min and max values will be swapped if min is greater than max. The resulting srcMin value cannot be 0.
func MapFloats ¶
MapFloats maps a list of floats to fall within a min/max range It returns the normalized list and does not change the original.
func MapLinExp ¶
MapLinExp maps a value within a linear min/max range to another exponential range. min and max values will be swapped if min is greater than max. The resulting dstMin value cannot be 0.
func MinMaxFloats ¶
MinMaxFloats returns the minimum and maximum values in a list of floats.
func NormalizeFloats ¶
NormalizeFloats normalizes a list of floats to fall within a 0.0 to 1.0 range. It returns the normalized list and does not change the original.
func Quantize ¶
Quantize quantizes a value in a range into a number of discrete steps in that range.
func RoundToNearest ¶
RoundToNearest rounds a number to the nearest multiple of a value.