Documentation
¶
Index ¶
- Constants
- func Abs[T numeric](x T) T
- func AbsMin[T numeric](a, b T) T
- func AcosDeg(x float64) float64
- func AsinDeg(x float64) float64
- func AtanDeg(x float64) float64
- func CalculateFraction(r float64, max int) (int, int)
- func CalculateFractionFromString(str string, sep string) float64
- func CalculateFractionToString(r float64, max int, sep string) string
- func CellSizeInWidth(width, spacing, marginMin, marginMax, count int) (size, start int)
- func CellSizeInWidthF(width, spacing, marginMin, marginMax float64, count int) (size, start float64)
- func CosDeg(degrees float64) float64
- func DegToRad(deg float64) float64
- func Downsample(samples []float64, newSize int) (ns []float64)
- func EaseInOut(t float64) float64
- func GetClosestNotSmaller(n float64, to []float64) float64
- func GetClosestTo(n float64, to []float64) float64
- func GetDistinctCountForKeyGroup(group, key any) int
- func GetNextOfSliceCombinations[S comparable](sets [][]S, current ...*S)
- func GetRangeMaxes[N int | int64 | float64](rs []Range[N]) []N
- func GetRangeMins[N int | int64 | float64](rs []Range[N]) []N
- func IndexOfMostFrequent(length int, compare func(i, j int) bool) int
- func InterpolatedArrayRatioAtT(arrayLength int, t float64) (ratio float64, index int)
- func LengthIntoDividePoints(len int) (points []int)
- func NiceDividesOf(s, e float64, max int, niceIncs []float64) (start, inc float64)
- func NiceNumberString(a any) (string, bool)
- func Normalized(n float64) (norm, scale float64)
- func RadToDeg(rad float64) float64
- func RatioOfIntRandomRounded(ratio float32, count int) int
- func RoundToAccuracy(f, accuracy float64) float64
- func RoundToMod(n, mod int) int
- func RoundToMod64(n, mod int64) int64
- func RoundToModF64(n, mod float64) float64
- func RoundUpToModF64(n, mod float64) float64
- func Sigmoid(n float64) float64
- func Sign[N cmp.Ordered](n N) float64
- func SinDeg(degrees float64) float64
- func Swap[N any](a, b *N)
- func TanDeg(degrees float64) float64
- func UniqueRandomNumbersMapInRange(maxValue, count int) (nums map[int]bool)
- type Number
- type Range
- func (r *Range[N]) Add(n N)
- func (r Range[N]) Added(n N) Range[N]
- func (r Range[N]) Clamped(n N) N
- func (r *Range[N]) Contract(n N)
- func (r *Range[N]) ContractExcludingInt(n int64)
- func (r Range[N]) Contracted(n N) Range[N]
- func (r Range[N]) ContractedExcludingInt(n int64) Range[N]
- func (r Range[N]) Length() N
- func (r *Range[N]) NiceString(digits int) string
- type RangeF64
- type Real
Constants ¶
const MathDegreesToMeters = (111.32 * 1000)
const MathMetersToDegrees = 1 / MathDegreesToMeters
Variables ¶
This section is empty.
Functions ¶
func CellSizeInWidth ¶
CellSizeInWidth calculates the size and start ois of a "cell" to fit in width with margins and spacing. It insets them a bit to account for integer widths/spacing not being able to fit in the exact space asked for.
func CellSizeInWidthF ¶
func CellSizeInWidthF(width, spacing, marginMin, marginMax float64, count int) (size, start float64)
CellSizeInWidthF is a convenience function to call CellSizeInWidth with float64's
func Downsample ¶
func EaseInOut ¶
EaseInOut makes t "ease in" gradually at 0, and easy out, flattening off near 1. Good for animations
func GetClosestNotSmaller ¶
func GetClosestTo ¶
func GetDistinctCountForKeyGroup ¶
For a given group and key GetDistinctCountForKeyGroup returns a increasing number for each key asked for within each group
func GetNextOfSliceCombinations ¶
func GetNextOfSliceCombinations[S comparable](sets [][]S, current ...*S)
GetNextOfSliceCombinations takes n slices of values, and the current value of each one. It increments to the next value of first set, or 0th and next of second set etc. Returning all possible combinations of the slices, wrapping to start over again. The slices need to always be given with the same order.
func IndexOfMostFrequent ¶
for length items, IndexOfMostFrequent compares them with each other and finds which one is used the most. It returns the index to an aribitrary item which is used the most.
func InterpolatedArrayRatioAtT ¶
InterpolatedArrayRatioAtT returns what index in an array t (0-1) is. ratio is how much (0-1) of index value should be used and vs rest in next index value
func LengthIntoDividePoints ¶
LengthIntoDividePoints finds the point that splits len in 2, then 2 points that split in 3, 4, etc, skipping ones already used. Final pass adds all not used yet. This can be used to do a binary search. First in slice is middle, then either side of it etc.
func NiceDividesOf ¶
NiceDividesOf divides s to e into minimum min parts. Good for dividing a graph into lines to show values on x and y-axis.
func NiceNumberString ¶
func Normalized ¶
Normalized returns a number scaled by 10's to be between 0 and 10. So 54321 becomes 5.4321 and 0.0123 becomes 1.23.
func RatioOfIntRandomRounded ¶
func RoundToAccuracy ¶
func RoundToMod ¶
func RoundToMod64 ¶
func RoundToModF64 ¶
func RoundUpToModF64 ¶
Types ¶
type Range ¶
type Range[N int | int64 | float64] struct { Valid bool `json:",omitempty"` Min N `json:",omitempty"` Max N `json:",omitempty"` }
func (*Range[N]) ContractExcludingInt ¶
func (Range[N]) Contracted ¶
Contracted reduces the range to only just include n at min or max, depending on which is nearer. An n outside does nothing.
func (Range[N]) ContractedExcludingInt ¶
ContractedExcludingInt is like Contracted, but reduces to, but doesn't include nearest int64