math

package
v0.0.0-...-0d409a9 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int | ~uint](
	n T,
) T

func BitwiseAnd

func BitwiseAnd[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint](a, b T) T

Bitwise and

func BitwiseLeftShift

func BitwiseLeftShift[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint, ST int | uint](a T, shift ST) T

Bitwise Left Shift

func BitwiseNot

func BitwiseNot[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint](a T) T

Bitwise not

func BitwiseOr

func BitwiseOr[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint](a, b T) T

Bitwise or

func BitwiseRightShift

func BitwiseRightShift[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint, ST int | uint](a T, shift ST) T

Bitwise Right Shift

func BitwiseXor

func BitwiseXor[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int | ~uint](a, b T) T

Bitwise xor

func Clamp

func Clamp[T constraints.Ordered](x, min, max T) T

Clamp clamps number within the inclusive lower and upper bounds.

func Floor

func Floor[F AnyFloat](x F) F

func Fmod

func Fmod[T ~float32 | ~float64](x, y T) T

func GetRandomNumber

func GetRandomNumber[
	T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int | ~uint | ~complex64 | ~complex128,
]() T

func IsInf

func IsInf[F AnyFloat](f F, sign int) bool

func IsNaN

func IsNaN[T ~float32 | ~float64](n T) bool

func Max

func Max[T constraints.Ordered](items ...T) T

func Min

func Min[T constraints.Ordered](items ...T) T

func Mod

func Mod[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int | ~uint](
	x T,
	y T,
) T

func Modf

func Modf[F AnyFloat](f F) (int F, frac F)

func NaN

func NaN[T ~float32 | ~float64]() T

func Product

func Product[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int | ~uint](values ...T) T

func Sum

func Sum[T ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int | ~uint](values ...T) T

Types

type AnyFloat

type AnyFloat interface {
	~float32 | ~float64
}

type Vector2

type Vector2[T VectorUnderlyingType] struct {
	X T
	Y T
}

Vector2D

func MakeVector2

func MakeVector2[T VectorUnderlyingType](x, y T) Vector2[T]

Make Vector2D

func OneVector2

func OneVector2[T VectorUnderlyingType]() Vector2[T]

One Vector2D

func SameVector2

func SameVector2[T VectorUnderlyingType](number T) Vector2[T]

Make Same Vector2D where all values of the vector are the same number specified

func ZeroVector2

func ZeroVector2[T VectorUnderlyingType]() Vector2[T]

Zero Vector2D

func (*Vector2[T]) Add

func (vec *Vector2[T]) Add(other Vector2[T])

Add other vector to current one

func (*Vector2[T]) AddWithinBounds

func (vec *Vector2[T]) AddWithinBounds(bounds Vector2[T], update Vector2[T])

AddWithinBounds Add update vector to current one within bounds of bounds vector

func (*Vector2[T]) AddWithinBoundsAndForceAbsolute

func (vec *Vector2[T]) AddWithinBoundsAndForceAbsolute(bounds Vector2[T], update Vector2[T])

AddWithinBoundsAndForceAbsolute Add update vector to current one within bounds of bounds vector and force value of vector to be positive

func (Vector2[T]) ContainsNaN

func (vec Vector2[T]) ContainsNaN() bool

ContainsNaN checks if vector contains NaN

func (*Vector2[T]) Divide

func (vec *Vector2[T]) Divide(other Vector2[T])

Divide current vector by other one

func (*Vector2[T]) Equal

func (vec *Vector2[T]) Equal(other Vector2[T]) bool

Equality check with other vector

func (*Vector2[T]) EqualWithinTolerance

func (vec *Vector2[T]) EqualWithinTolerance(other Vector2[T], tolerance Vector2[T]) bool

EqualWithinTolerance check if current vector is within tolerance vector of other vector

func (*Vector2[T]) FromString

func (vec *Vector2[T]) FromString(v string)

Change values of current vector to values from string representation

func (*Vector2[T]) Multiply

func (vec *Vector2[T]) Multiply(other Vector2[T])

Multiply other vector with current one

func (Vector2[T]) String

func (vec Vector2[T]) String() string

String representation of vector

func (*Vector2[T]) Substract

func (vec *Vector2[T]) Substract(other Vector2[T])

Substract other vector from current one

func (Vector2[T]) ToString

func (vec Vector2[T]) ToString() string

String representation of vector

func (Vector2[T]) ToTuple

func (vec Vector2[T]) ToTuple() (x, y T)

ToTuple get tuple of cordinates of vector

type Vector3

type Vector3[T VectorUnderlyingType] struct {
	X T
	Y T
	Z T
}

Vector3D

func MakeVector3

func MakeVector3[T VectorUnderlyingType](x, y, z T) Vector3[T]

Make Vector3D

func OneVector3

func OneVector3[T VectorUnderlyingType]() Vector3[T]

One Vector3D

func SameVector3

func SameVector3[T VectorUnderlyingType](number T) Vector3[T]

Make Same Vector3D where all values of the vector are the same number specified

func ZeroVector3

func ZeroVector3[T VectorUnderlyingType]() Vector3[T]

Zero Vector3D

func (*Vector3[T]) Add

func (vec *Vector3[T]) Add(other Vector3[T])

Add other vector to current one

func (*Vector3[T]) AddWithinBounds

func (vec *Vector3[T]) AddWithinBounds(bounds Vector3[T], update Vector3[T])

AddWithinBounds Add update vector to current one within bounds of bounds vector

func (*Vector3[T]) AddWithinBoundsAndForceAbsolute

func (vec *Vector3[T]) AddWithinBoundsAndForceAbsolute(bounds Vector3[T], update Vector3[T])

AddWithinBoundsAndForceAbsolute Add update vector to current one within bounds of bounds vector and force value of vector to be positive

func (Vector3[T]) ContainsNaN

func (vec Vector3[T]) ContainsNaN() bool

ContainsNaN checks if vector contains NaN

func (*Vector3[T]) Divide

func (vec *Vector3[T]) Divide(other Vector3[T])

Divide current vector by other one

func (*Vector3[T]) Equal

func (vec *Vector3[T]) Equal(other Vector3[T]) bool

Equality check with other vector

func (*Vector3[T]) EqualWithinTolerance

func (vec *Vector3[T]) EqualWithinTolerance(other Vector3[T], tolerance Vector3[T]) bool

EqualWithinTolerance check if current vector is within tolerance vector of other vector

func (*Vector3[T]) FromString

func (vec *Vector3[T]) FromString(v string)

Change values of current vector to values from string representation

func (*Vector3[T]) Multiply

func (vec *Vector3[T]) Multiply(other Vector3[T])

Multiply other vector with current one

func (Vector3[T]) String

func (vec Vector3[T]) String() string

String representation of vector

func (*Vector3[T]) Substract

func (vec *Vector3[T]) Substract(other Vector3[T])

Substract other vector from current one

func (Vector3[T]) ToString

func (vec Vector3[T]) ToString() string

String representation of vector

func (Vector3[T]) ToTuple

func (vec Vector3[T]) ToTuple() (x, y, z T)

ToTuple get tuple of cordinates of vector

type Vector4

type Vector4[T VectorUnderlyingType] struct {
	X T
	Y T
	Z T
	W T
}

Vector4D

func MakeVector4

func MakeVector4[T VectorUnderlyingType](x, y, z, w T) Vector4[T]

Make Vector4D

func OneVector4

func OneVector4[T VectorUnderlyingType]() Vector4[T]

One Vector2D

func SameVector4

func SameVector4[T VectorUnderlyingType](number T) Vector4[T]

Make Same Vector4D where all values of the vector are the same number specified

func ZeroVector4

func ZeroVector4[T VectorUnderlyingType]() Vector4[T]

Zero Vector2D

func (*Vector4[T]) Add

func (vec *Vector4[T]) Add(other Vector4[T])

Add other vector to current one

func (*Vector4[T]) AddWithinBounds

func (vec *Vector4[T]) AddWithinBounds(bounds Vector4[T], update Vector4[T])

AddWithinBounds Add update vector to current one within bounds of bounds vector

func (*Vector4[T]) AddWithinBoundsAndForceAbsolute

func (vec *Vector4[T]) AddWithinBoundsAndForceAbsolute(bounds Vector4[T], update Vector4[T])

AddWithinBoundsAndForceAbsolute Add update vector to current one within bounds of bounds vector and force value of vector to be positive

func (Vector4[T]) ContainsNaN

func (vec Vector4[T]) ContainsNaN() bool

ContainsNaN checks if vector contains NaN

func (*Vector4[T]) Divide

func (vec *Vector4[T]) Divide(other Vector4[T])

Divide current vector by other one

func (*Vector4[T]) Equal

func (vec *Vector4[T]) Equal(other Vector4[T]) bool

Equality check with other vector

func (*Vector4[T]) EqualWithinTolerance

func (vec *Vector4[T]) EqualWithinTolerance(other Vector4[T], tolerance Vector4[T]) bool

EqualWithinTolerance check if current vector is within tolerance vector of other vector

func (*Vector4[T]) FromString

func (vec *Vector4[T]) FromString(v string)

Change values of current vector to values from string representation

func (*Vector4[T]) Multiply

func (vec *Vector4[T]) Multiply(other Vector4[T])

Multiply other vector with current one

func (Vector4[T]) String

func (vec Vector4[T]) String() string

String representation of vector

func (*Vector4[T]) Substract

func (vec *Vector4[T]) Substract(other Vector4[T])

Substract other vector from current one

func (Vector4[T]) ToString

func (vec Vector4[T]) ToString() string

String representation of vector

func (Vector4[T]) ToTuple

func (vec Vector4[T]) ToTuple() (x, y, z, w T)

ToTuple get tuple of cordinates of vector

type VectorUnderlyingType

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

Jump to

Keyboard shortcuts

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