util

package
v0.0.0-...-20810c9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EPSILON = float32(0.00001)

Functions

func Abs

func Abs[D Numeric](v D) D

Computes the absolute value of the given value.

func Acos

func Acos[D Numeric](rad D) D

Computes the arcosine of the given radians.

func Asin

func Asin[D Numeric](rad D) D

Computes the arcsine of the given radians.

func Assert

func Assert(condition bool, messageFormat string, args ...any)

func Atan2

func Atan2[D Numeric](y D, x D) D

Computes the Atan2 of the given radians.

func Ceil

func Ceil[D Numeric](v D) D

Computes the ceil of the given value.

func Choose

func Choose[D Integer](n D, m D) D

Computes the number of combinations of size m that can be made with n things.

func Clamp

func Clamp[D Numeric](v D, min D, max D) D

Returns v but no larger than the max or smaller than the min.

func Clone

func Clone[V any](nilable *V) *V

func Coalesce

func Coalesce[V any](nilable *V, nonNil V) V

func Coalesce2

func Coalesce2[V any](nilable1 *V, nilable2 *V, nonNil V) V

func CoalesceJoin

func CoalesceJoin[V any](a, b V, swap bool, isNil func(V) bool, join func(V, V) V) V

func Copy

func Copy(dst any, src any)

func CopySign

func CopySign[D Numeric](value D, sign D) D

Returns "value" with the sign of the value "sign"

func Cos

func Cos[D Numeric](rad D) D

Computes the cosine of the given radians.

func CosSin

func CosSin[D Numeric](rad D) (cos D, sin D)

Returns the cosine & sine of the given radians.

func Delta

func Delta[D Numeric](start, end, value D) float32

Computes the delta of v between a start and end value where a delta of 0 is at start and a delta of 1 is at end.

func Div

func Div[D Numeric](a D, b D) D

Divides a by b, unless b is zero then zero is returned.

func Down

func Down[D Numeric](v D) D

Rounds the value to the smallest absolute value. Down(4.5)=4, Down(-4.5)=-4, Down(3)=3

func Equal

func Equal[D Numeric](a, b D) bool

Returns if two numbers are equal enough (based on EPSILON)

func Factorial

func Factorial[D Numeric](x D) D

Computes the factorial of the given number. ex: Factorial(5) = 5*4*3*2*1

func Floor

func Floor[D Numeric](v D) D

Computes the floor of the given value.

func Gcd

func Gcd[D Integer](a D, b D) D

Calculates the greatest common denominator between two integer numbers.

func If

func If[V any](condition bool, trueValue, falseValue V) V

func Lerp

func Lerp[D Numeric](start, end D, delta float32) D

Does a lineary interpolation between

func MapKeys

func MapKeys[K comparable, V any](m map[K]V) []K

func MapValues

func MapValues[K comparable, V any](m map[K]V) []V

func Max

func Max[D Numeric](a D, b D) D

Returns the largest number between a & b.

func MaxMagnitude

func MaxMagnitude[D Numeric](value D, max D) D

Constrains the absolute value of `value` to be no larger than max.

func Min

func Min[D Numeric](a D, b D) D

Returns the smallest number between a & b.

func MinMagnitude

func MinMagnitude[D Numeric](value D, min D) D

Constrains the absolute value of `value` to be no smaller than min (unless value is zero)

func MinMax

func MinMax[D Numeric](a D, b D) (D, D)

Returns the smallest then largest number between a & b.

func Pow

func Pow[D Numeric](x, y D) D

Returns the cosine & sine of the given radians.

func QuadraticFormula

func QuadraticFormula(a, b, c, none float32) float32

Computes the quadratic formula between a, b, and c. If it can't be computed then none is returned.

func Sign

func Sign[D Numeric](v D) int

Computes the sign of the given number where 0 has a sign of 0, a negative number returns -1 and a positive number returns 1.

func Sin

func Sin[D Numeric](rad D) D

Computes the sine of the given radians.

func SliceAppendAt

func SliceAppendAt[D any](target []D, at int, values []D) []D

func SliceCopy

func SliceCopy[E any](slice []E) []E

func SliceEnsureSize

func SliceEnsureSize[V any](slice []V, size int) []V

func SliceIndexOf

func SliceIndexOf[V comparable](slice []V, value V) int

func SliceMap

func SliceMap[S any, T any](source []S, transform func(value S) T) []T

func SliceMove

func SliceMove[V any](slice []V, from, to int)

func SliceRemove

func SliceRemove[E comparable](slice []E, value E) []E

func SliceRemoveAt

func SliceRemoveAt[E any](slice []E, index int) []E

func SliceRemoveAtReplace

func SliceRemoveAtReplace[E any](slice []E, index int) []E

func SliceResize

func SliceResize[V any](slice []V, size int) []V

func SliceReverse

func SliceReverse[E any](s []E)

func SliceSorted

func SliceSorted[E any](slice []E, isLess func(E, E) bool) []E

func Sq

func Sq[D Numeric](x D) D

Computes the square of the value

func Sqrt

func Sqrt[D Numeric](v D) D

Computes the square root of the given number.

func Up

func Up[D Numeric](v D) D

Rounds the value to the largest absolute value. Up(4.5)=5, Up(-4.5)=-5, Up(3)=3

Types

type Flags

type Flags[T constraints.Integer] struct {
	// contains filtered or unexported fields
}

Utility struct for typed bitwise operations.

func (*Flags[T]) Clear

func (f *Flags[T]) Clear()

Clears all flags from this set.

func (Flags[T]) Get

func (f Flags[T]) Get() T

Returns the current integer value in this set.

func (Flags[T]) Is

func (f Flags[T]) Is(match Match[T]) bool

Returns whether this set of flags matches the given Match function.

func (Flags[T]) IsEmpty

func (f Flags[T]) IsEmpty() bool

Returns whether this set is empty.

func (*Flags[T]) Only

func (f *Flags[T]) Only(flags T)

Changes this set to be only values that are shared between it and the flags.

func (*Flags[T]) Remove

func (f *Flags[T]) Remove(flags T)

Removes the flags from this set.

func (*Flags[T]) Set

func (f *Flags[T]) Set(flags T)

Adds the flags to this set.

func (*Flags[T]) Toggle

func (f *Flags[T]) Toggle(flags T)

Toggles the flags in this set.

type Incrementor

type Incrementor[I constraints.Ordered] struct {
	// contains filtered or unexported fields
}

func NewIncrementor

func NewIncrementor[I constraints.Ordered](initial, increment I) Incrementor[I]

func (*Incrementor[I]) Get

func (i *Incrementor[I]) Get() I

func (Incrementor[I]) Peek

func (i Incrementor[I]) Peek() I

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Match

type Match[T constraints.Integer | constraints.Unsigned] func(value T) bool

A match is a function which is given a single integer and returns whether it matches some criteria.

func MatchAll

func MatchAll[T constraints.Integer | constraints.Unsigned](test T) Match[T]

Creates a match which returns true if all bits in test are on in a given value.

func MatchAlways

func MatchAlways[T constraints.Integer | constraints.Unsigned]() Match[T]

func MatchAnd

func MatchAnd[T constraints.Integer | constraints.Unsigned](ands ...Match[T]) Match[T]

Creates a match which returns true if all given matches return true.

func MatchAny

func MatchAny[T constraints.Integer | constraints.Unsigned](test T) Match[T]

Creates a match which returns true if any bits in test are in a given value.

func MatchEmpty

func MatchEmpty[T constraints.Integer | constraints.Unsigned]() Match[T]

Creates a match which returns true when a given value is zero.

func MatchExact

func MatchExact[T constraints.Integer | constraints.Unsigned](test T) Match[T]

Creates a match which returns true if a given value and test are equal.

func MatchNone

func MatchNone[T constraints.Integer | constraints.Unsigned](test T) Match[T]

Creates a match which returns true if there are no bits in common with a given value.

func MatchNot

func MatchNot[T constraints.Integer | constraints.Unsigned](not Match[T]) Match[T]

Creaes a match which returns the negation of given match.

func MatchOnly

func MatchOnly[T constraints.Integer | constraints.Unsigned](test T) Match[T]

Creates a match which returns true if all bits in a given value are on in test.

func MatchOr

func MatchOr[T constraints.Integer | constraints.Unsigned](ors ...Match[T]) Match[T]

Creates a match which returns true if any given matches return true.

type Numeric

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64
}

Jump to

Keyboard shortcuts

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