num

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Clockwise indicates a clockwise rotaion.
	Clockwise = 1
	// CounterClockwise indicates a counter-clockwise rotaion.
	CounterClockwise = -1
	// NoRotation indicates two angles are same.
	NoRotation = 0
)

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(from, to float64) float64

DifferenceDegrees returns the absolute shortest angular difference.

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, to float64) float64

RotationDirection calculates the optimal rotation direction. It uses math.Remainder to find the shortest signed 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 [9]float64

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) Column

func (m Matrix3) Column(n int) Vector3

Column returns the n-th column of the matrix.

func (Matrix3) Inverse

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

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

func (Matrix3) Mul

func (m Matrix3) Mul(v Vector3) Vector3

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

func (Matrix3) Row

func (m Matrix3) Row(n int) Vector3

Row returns the n-th row of the matrix.

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) Dot

func (v Vector3) Dot(vec Vector3) float64

Dot multiplies v Vector3 with given Vector3 and returns a float64.

func (Vector3) Map

func (v Vector3) Map(f func(float64) float64) Vector3

Map returns a new Vector3 where each component of v has been transformed by the given func f. Returns a new Vector3.

func (Vector3) MulElems

func (v Vector3) MulElems(vec Vector3) Vector3

MulElems multiplies v Vector3 with given Vector3 element-wise and returns a new Vector3.

func (Vector3) Scaled

func (v Vector3) Scaled(s float64) Vector3

Scaled multiplies all values using a scalar float64 and retuns a new Vector3.

func (Vector3) String

func (v Vector3) String() string

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