num

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp[T cmp.Ordered](low, high, value T) T

Clamp takes in a value and two thresholds. If the value is smaller than the low threshold, it returns the low threshold. If it's bigger than the high threshold it returns the high threshold. Otherwise it returns the value.

func Degree

func Degree(rad float64) float64

Degree converts an angle in radians to degrees.

func DifferenceDegrees

func DifferenceDegrees(a, b float64) float64

DifferenceDegrees returns the shortest angular difference between two angles in degrees.

func Lerp

func Lerp(start float64, stop float64, amount float64) float64

Lerp is The linear interpolation function.

func NormalizeDegree

func NormalizeDegree(angle float64) float64

NormalizeDegree takes an angle in degrees and normalizes it to the range 0-360.

func NormalizeDegreeInt

func NormalizeDegreeInt(angle int) int

NormalizeDegreeInt takes an angle in degrees and normalizes it to the range 0-360.

func NormalizeRadian

func NormalizeRadian(angle float64) float64

NormalizeRadian takes an angle in degrees and normalizes it to the range 0-360.

func Radian

func Radian(deg float64) float64

Radian converts an angle in degrees to radians.

func RotationDirection

func RotationDirection(from float64, to float64) float64

RotationDirection calculates the optimal rotation direction between two angles.

Given two angles 'from' and 'to' in degrees, it returns:

-1.0 for clockwise rotation (shorter path)
 1.0 for counter-clockwise rotation (shorter path)
 0.0 if the angles are identical

The function considers all three possible paths (direct, +360°, -360°) and chooses the one with the smallest absolute angular distance.

func Sign

func Sign[T signed](n T) T

Sign compares two ordered values n. It returns -1 if n < 0, 1 if n > 0, and 0 if n == 0.

func SignCmp

func SignCmp[T cmp.Ordered](a, b T) int

SignCmp compares two ordered values a and b. It returns -1 if a < b, 1 if a > b, and 0 if a == b.

Types

type Matrix3

type Matrix3 [3]Vector3

Matrix3 defines a 3x3 matrix of float64 values.

func NewMatrix3

func NewMatrix3(x1, y1, z1, x2, y2, z2, x3, y3, z3 float64) Matrix3

NewMatrix3 creates a 3x3 Matrix3.

func (Matrix3) Inverse

func (m Matrix3) Inverse() (Matrix3, bool)

Inverse inverses the M Matrix3. Returns false if m Matrix3 is not inversable.

func (Matrix3) Multiply

func (m Matrix3) Multiply(v Vector3) Vector3

Multiply applies the matrix to a 3D vector and returns the resulting vector.

func (Matrix3) String

func (m Matrix3) String() string

String implements Stringer method.

func (Matrix3) Transpose

func (m Matrix3) Transpose() Matrix3

Transpose transposes the Matrix3.

type Vector3

type Vector3 [3]float64

Vector3 defines a 3D vector.

func NewVector

func NewVector(v VectorLike) Vector3

NewVector create new 3D vector: Vector3.

func NewVector3

func NewVector3(x, y, z float64) Vector3

NewVector3 create new 3D vector: Vector3.

func (Vector3) Add

func (v Vector3) Add(vec Vector3) Vector3

Add adds values of v Vector3 with given Vector3 and returns new Vector3.

func (Vector3) MultiplyScalar

func (v Vector3) MultiplyScalar(s float64) Vector3

MultiplyScalar multiply all values using a scalar float64 and retuns a new Vector3.

func (Vector3) Transform

func (v Vector3) Transform(f func(float64) float64) Vector3

Transform returns a new Vector3 where each component of v has been transformed by the given func f. The func f is applied to each of v's components independently, producing a new Vector3 without modifying the original.

func (Vector3) Values

func (v Vector3) Values() (float64, float64, float64)

Values retuns all values of underlying Vector3.

type VectorLike

type VectorLike interface {
	Values() (float64, float64, float64)
}

VectorLike is any data that has 3 float64 values. Usually a color model.

Jump to

Keyboard shortcuts

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