zmath

package
v0.0.0-...-0906e08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2025 License: MPL-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const MathDegreesToMeters = (111.32 * 1000)
View Source
const MathMetersToDegrees = 1 / MathDegreesToMeters

Variables

This section is empty.

Functions

func Abs

func Abs[T numeric](x T) T

func AbsMin

func AbsMin[T numeric](a, b T) T

func AcosDeg

func AcosDeg(x float64) float64

func AsinDeg

func AsinDeg(x float64) float64

func AtanDeg

func AtanDeg(x float64) float64

func CalculateFraction

func CalculateFraction(r float64, max int) (int, int)

func CalculateFractionFromString

func CalculateFractionFromString(str string, sep string) float64

func CalculateFractionToString

func CalculateFractionToString(r float64, max int, sep string) string

func CellSizeInWidth

func CellSizeInWidth(width, spacing, marginMin, marginMax, count int) (size, start int)

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 CosDeg

func CosDeg(degrees float64) float64

func DegToRad

func DegToRad(deg float64) float64

func Downsample

func Downsample(samples []float64, newSize int) (ns []float64)

func EaseInOut

func EaseInOut(t float64) float64

EaseInOut makes t "ease in" gradually at 0, and easy out, flattening off near 1. Good for animations

func GetClosestNotSmaller

func GetClosestNotSmaller(n float64, to []float64) float64

func GetClosestTo

func GetClosestTo(n float64, to []float64) float64

func GetDistinctCountForKeyGroup

func GetDistinctCountForKeyGroup(group, key any) int

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 GetRangeMaxes

func GetRangeMaxes[N int | int64 | float64](rs []Range[N]) []N

func GetRangeMins

func GetRangeMins[N int | int64 | float64](rs []Range[N]) []N

func IndexOfMostFrequent

func IndexOfMostFrequent(length int, compare func(i, j int) bool) int

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

func InterpolatedArrayRatioAtT(arrayLength int, t float64) (ratio float64, index int)

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

func LengthIntoDividePoints(len int) (points []int)

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

func NiceDividesOf(s, e float64, max int, niceIncs []float64) (start, inc float64)

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 NiceNumberString(a any) (string, bool)

func Normalized

func Normalized(n float64) (norm, scale float64)

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 RadToDeg

func RadToDeg(rad float64) float64

func RatioOfIntRandomRounded

func RatioOfIntRandomRounded(ratio float32, count int) int

func RoundToAccuracy

func RoundToAccuracy(f, accuracy float64) float64

func RoundToMod

func RoundToMod(n, mod int) int

func RoundToMod64

func RoundToMod64(n, mod int64) int64

func RoundToModF64

func RoundToModF64(n, mod float64) float64

func RoundUpToModF64

func RoundUpToModF64(n, mod float64) float64

func Sigmoid

func Sigmoid(n float64) float64

func Sign

func Sign[N cmp.Ordered](n N) float64

func SinDeg

func SinDeg(degrees float64) float64

func Swap

func Swap[N any](a, b *N)

func TanDeg

func TanDeg(degrees float64) float64

func UniqueRandomNumbersMapInRange

func UniqueRandomNumbersMapInRange(maxValue, count int) (nums map[int]bool)

Types

type Number

type Number interface {
	zint.Integer | ~float32 | ~float64
}

type Range

type Range[N int | int64 | float64] struct {
	Valid bool `json:",omitempty"`
	Min   N    `json:",omitempty"`
	Max   N    `json:",omitempty"`
}

func MakeRange

func MakeRange[N int | int64 | float64](min, max N) Range[N]

func (*Range[N]) Add

func (r *Range[N]) Add(n N)

func (Range[N]) Added

func (r Range[N]) Added(n N) Range[N]

func (Range[N]) Clamped

func (r Range[N]) Clamped(n N) N

func (*Range[N]) Contract

func (r *Range[N]) Contract(n N)

func (*Range[N]) ContractExcludingInt

func (r *Range[N]) ContractExcludingInt(n int64)

func (Range[N]) Contracted

func (r Range[N]) Contracted(n N) Range[N]

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

func (r Range[N]) ContractedExcludingInt(n int64) Range[N]

ContractedExcludingInt is like Contracted, but reduces to, but doesn't include nearest int64

func (Range[N]) Length

func (r Range[N]) Length() N

func (*Range[N]) NiceString

func (r *Range[N]) NiceString(digits int) string

type RangeF64

type RangeF64 = Range[float64]

type Real

type Real interface {
	~float32 | ~float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL