sprec

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 2 Imported by: 9

Documentation

Overview

Package sprec represents a mathematics library for working with single precision types.

Index

Constants

View Source
const (
	Pi      = float32(math.Pi)
	Epsilon = float32(0.000001)
)

Variables

This section is empty.

Functions

func Abs

func Abs[T ~float32](value T) T

func Ceil added in v0.9.0

func Ceil[T ~float32](value T) T

func Clamp

func Clamp[T ~float32](value, lower, upper T) T

func Cos

func Cos(angle Angle) float32

func Eq

func Eq(a, b float32) bool

func EqEps

func EqEps(a, b, epsilon float32) bool

func Floor added in v0.9.0

func Floor[T ~float32](value T) T

func IsNegative added in v0.9.0

func IsNegative[T ~float32](value T) bool

func IsValid added in v0.9.0

func IsValid[T ~float32](value T) bool

func Max

func Max[T ~float32](a, b T) T

func Min

func Min[T ~float32](a, b T) T

func Mix added in v0.2.0

func Mix[T ~float32](a, b T, amount float32) T

func Mod added in v0.9.0

func Mod(a, b float32) float32

func Pow added in v0.9.0

func Pow(a, b float32) float32

func QuatDot added in v0.4.0

func QuatDot(a, b Quat) float32

func Sign

func Sign(value float32) float32

func Sin

func Sin(angle Angle) float32

func Sqrt

func Sqrt(value float32) float32

func Tan

func Tan(angle Angle) float32

func Vec2Dot

func Vec2Dot(a, b Vec2) float32

func Vec3Dot

func Vec3Dot(a, b Vec3) float32

func Vec4Dot added in v0.3.0

func Vec4Dot(a, b Vec4) float32

Types

type Angle

type Angle float32

func Acos added in v0.4.0

func Acos(cs float32) Angle

func Asin added in v0.4.0

func Asin(sn float32) Angle

func Atan2 added in v0.9.0

func Atan2(y, x float32) Angle

func Degrees

func Degrees(degrees float32) Angle

func Radians

func Radians(radians float32) Angle

func (Angle) Degrees

func (a Angle) Degrees() float32

func (Angle) IsInf added in v0.7.0

func (a Angle) IsInf() bool

func (Angle) IsNaN added in v0.7.0

func (a Angle) IsNaN() bool

func (Angle) Radians

func (a Angle) Radians() float32

type Mat3

type Mat3 struct {
	M11, M12, M13 float32
	M21, M22, M23 float32
	M31, M32, M33 float32
}

func ColumnMajorArrayToMat3 added in v0.3.0

func ColumnMajorArrayToMat3(values [9]float32) Mat3

func FastInverseMat3

func FastInverseMat3(m Mat3) Mat3

FastInverseMat3 calculates the inverse of the matrix with a few caveats.

The matrix should be a transformation one that was constructed through the multiplication of one or more of the following transformations: identity, translation, rotation.

For all other scenarios (e.g. a scale transformation was used), the InverseMat3 method should be used instead, though it will be slower.

func IdentityMat3

func IdentityMat3() Mat3

func InverseMat3

func InverseMat3(m Mat3) Mat3

InverseMat3 calculates the inverse of the matrix.

The behavior is undefined if the matrix is not reversible (i.e. has a zero determinant).

func Mat3MultiProd

func Mat3MultiProd(first Mat3, others ...Mat3) Mat3

func Mat3Prod

func Mat3Prod(left, right Mat3) Mat3

func NewMat3

func NewMat3(
	m11, m12, m13 float32,
	m21, m22, m23 float32,
	m31, m32, m33 float32,
) Mat3

func OrthoMat3

func OrthoMat3(left, right, top, bottom float32) Mat3

func RotationMat3

func RotationMat3(angle Angle) Mat3

func RowMajorArrayToMat3 added in v0.3.0

func RowMajorArrayToMat3(values [9]float32) Mat3

func ScaleMat3

func ScaleMat3(x, y float32) Mat3

func TransformationMat3

func TransformationMat3(orientX, orientY, translation Vec2) Mat3

func TranslationMat3

func TranslationMat3(x, y float32) Mat3

func TransposedMat3 added in v0.5.0

func TransposedMat3(m Mat3) Mat3

func ZeroMat3

func ZeroMat3() Mat3

func (Mat3) Column1 added in v0.3.0

func (m Mat3) Column1() Vec3

func (Mat3) Column2 added in v0.3.0

func (m Mat3) Column2() Vec3

func (Mat3) Column3 added in v0.3.0

func (m Mat3) Column3() Vec3

func (Mat3) ColumnMajorArray added in v0.3.0

func (m Mat3) ColumnMajorArray() [9]float32

func (Mat3) GoString

func (m Mat3) GoString() string

func (Mat3) IsInf added in v0.7.0

func (m Mat3) IsInf() bool

func (Mat3) IsNaN added in v0.7.0

func (m Mat3) IsNaN() bool

func (Mat3) OrientationX

func (m Mat3) OrientationX() Vec2

func (Mat3) OrientationY

func (m Mat3) OrientationY() Vec2

func (Mat3) Row1 added in v0.3.0

func (m Mat3) Row1() Vec3

func (Mat3) Row2 added in v0.3.0

func (m Mat3) Row2() Vec3

func (Mat3) Row3 added in v0.3.0

func (m Mat3) Row3() Vec3

func (Mat3) RowMajorArray added in v0.3.0

func (m Mat3) RowMajorArray() [9]float32

func (Mat3) Translation

func (m Mat3) Translation() Vec2

type Mat4

type Mat4 struct {
	M11, M12, M13, M14 float32
	M21, M22, M23, M24 float32
	M31, M32, M33, M34 float32
	M41, M42, M43, M44 float32
}

func ColumnMajorArrayToMat4 added in v0.3.0

func ColumnMajorArrayToMat4(values [16]float32) Mat4

func FastInverseMat4

func FastInverseMat4(m Mat4) Mat4

FastInverseMat4 calculates the inverse of the matrix with a few caveats.

The matrix should be a transformation one that was constructed through the multiplication of one or more of the following transformations: identity, translation, rotation.

For all other scenarios (e.g. a scale transformation was used), the InverseMat4 method should be used instead, though it will be slower.

func IdentityMat4

func IdentityMat4() Mat4

func InverseMat4

func InverseMat4(m Mat4) Mat4

InverseMat4 calculates the inverse of the matrix.

The behavior is undefined if the matrix is not reversible (i.e. has a zero determinant).

func Mat4MultiProd

func Mat4MultiProd(first Mat4, others ...Mat4) Mat4

func Mat4Prod

func Mat4Prod(left, right Mat4) Mat4

func NewMat4

func NewMat4(
	m11, m12, m13, m14 float32,
	m21, m22, m23, m24 float32,
	m31, m32, m33, m34 float32,
	m41, m42, m43, m44 float32,
) Mat4

func OrientationMat4

func OrientationMat4(orientX, orientY, orientZ Vec3) Mat4

func OrthoMat4

func OrthoMat4(left, right, top, bottom, near, far float32) Mat4

func PerspectiveMat4

func PerspectiveMat4(left, right, bottom, top, near, far float32) Mat4

func RotationMat4

func RotationMat4(angle Angle, x, y, z float32) Mat4

func RowMajorArrayToMat4 added in v0.3.0

func RowMajorArrayToMat4(values [16]float32) Mat4

func ScaleMat4

func ScaleMat4(x, y, z float32) Mat4

func TRSMat4 added in v0.3.0

func TRSMat4(translation Vec3, rotation Quat, scale Vec3) Mat4

func TransformationMat4

func TransformationMat4(orientX, orientY, orientZ, translation Vec3) Mat4

func TranslationMat4

func TranslationMat4(x, y, z float32) Mat4

func TransposedMat4 added in v0.5.0

func TransposedMat4(m Mat4) Mat4

func ZeroMat4

func ZeroMat4() Mat4

func (Mat4) Column1 added in v0.3.0

func (m Mat4) Column1() Vec4

func (Mat4) Column2 added in v0.3.0

func (m Mat4) Column2() Vec4

func (Mat4) Column3 added in v0.3.0

func (m Mat4) Column3() Vec4

func (Mat4) Column4 added in v0.3.0

func (m Mat4) Column4() Vec4

func (Mat4) ColumnMajorArray

func (m Mat4) ColumnMajorArray() [16]float32

func (Mat4) GoString

func (m Mat4) GoString() string

func (Mat4) IsInf added in v0.7.0

func (m Mat4) IsInf() bool

func (Mat4) IsNaN added in v0.7.0

func (m Mat4) IsNaN() bool

func (Mat4) OrientationX

func (m Mat4) OrientationX() Vec3

func (Mat4) OrientationY

func (m Mat4) OrientationY() Vec3

func (Mat4) OrientationZ

func (m Mat4) OrientationZ() Vec3

func (Mat4) Rotation added in v0.5.0

func (m Mat4) Rotation() Quat

Rotation returns the rotation that is represented by this matrix. NOTE: This function assumes that the matrix has identity scale. If you want to get the rotation of a matrix that has non-identity scale, consider using the TRS method.

func (Mat4) Row1 added in v0.3.0

func (m Mat4) Row1() Vec4

func (Mat4) Row2 added in v0.3.0

func (m Mat4) Row2() Vec4

func (Mat4) Row3 added in v0.3.0

func (m Mat4) Row3() Vec4

func (Mat4) Row4 added in v0.3.0

func (m Mat4) Row4() Vec4

func (Mat4) RowMajorArray

func (m Mat4) RowMajorArray() [16]float32

func (Mat4) Scale added in v0.2.0

func (m Mat4) Scale() Vec3

func (Mat4) TRS added in v0.5.0

func (m Mat4) TRS() (Vec3, Quat, Vec3)

func (Mat4) Translation

func (m Mat4) Translation() Vec3

type Quat

type Quat struct {
	W float32
	X float32
	Y float32
	Z float32
}

func ConjugateQuat

func ConjugateQuat(q Quat) Quat

func IdentityQuat

func IdentityQuat() Quat

func InverseQuat

func InverseQuat(q Quat) Quat

func NegativeQuat added in v0.4.0

func NegativeQuat(q Quat) Quat

func NewQuat

func NewQuat(w, x, y, z float32) Quat

func QuatDiff added in v0.4.0

func QuatDiff(second, first Quat, shortest bool) Quat

func QuatLerp added in v0.4.0

func QuatLerp(first, second Quat, t float32) Quat

func QuatPow added in v0.4.0

func QuatPow(q Quat, pow float32) Quat

func QuatProd

func QuatProd(first, second Quat) Quat

func QuatScalarProd

func QuatScalarProd(q Quat, value float32) Quat

func QuatScalarQuot

func QuatScalarQuot(q Quat, value float32) Quat

func QuatSlerp added in v0.4.0

func QuatSlerp(first, second Quat, t float32) Quat

func RotationQuat

func RotationQuat(angle Angle, direction Vec3) Quat

func UnitQuat

func UnitQuat(q Quat) Quat

func (Quat) GoString

func (q Quat) GoString() string

func (Quat) IsIdentity added in v0.7.0

func (q Quat) IsIdentity() bool

func (Quat) IsInf added in v0.7.0

func (q Quat) IsInf() bool

func (Quat) IsNaN added in v0.7.0

func (q Quat) IsNaN() bool

func (Quat) Norm

func (q Quat) Norm() float32

func (Quat) OrientationX

func (q Quat) OrientationX() Vec3

func (Quat) OrientationY

func (q Quat) OrientationY() Vec3

func (Quat) OrientationZ

func (q Quat) OrientationZ() Vec3

func (Quat) SqrNorm

func (q Quat) SqrNorm() float32

type Vec2

type Vec2 struct {
	X float32
	Y float32
}

func ArrayToVec2 added in v0.3.0

func ArrayToVec2(array [2]float32) Vec2

func BasisXVec2

func BasisXVec2() Vec2

func BasisYVec2

func BasisYVec2() Vec2

func InverseVec2

func InverseVec2(vector Vec2) Vec2

func NewVec2

func NewVec2(x, y float32) Vec2

func NormalVec2 added in v0.7.0

func NormalVec2(vector Vec2) Vec2

func ResizedVec2

func ResizedVec2(vector Vec2, newLength float32) Vec2

func UnitVec2

func UnitVec2(vector Vec2) Vec2

func Vec2Diff

func Vec2Diff(a, b Vec2) Vec2

func Vec2Lerp added in v0.4.0

func Vec2Lerp(a, b Vec2, t float32) Vec2

func Vec2MultiDiff added in v0.7.0

func Vec2MultiDiff(first Vec2, others ...Vec2) Vec2

func Vec2MultiSum added in v0.7.0

func Vec2MultiSum(first Vec2, others ...Vec2) Vec2

func Vec2Prod

func Vec2Prod(vector Vec2, value float32) Vec2

func Vec2Quot

func Vec2Quot(vector Vec2, value float32) Vec2

func Vec2Sum

func Vec2Sum(a, b Vec2) Vec2

func ZeroVec2

func ZeroVec2() Vec2

func (Vec2) GoString

func (v Vec2) GoString() string

func (Vec2) IsInf added in v0.7.0

func (v Vec2) IsInf() bool

func (Vec2) IsNaN added in v0.7.0

func (v Vec2) IsNaN() bool

func (Vec2) IsZero

func (v Vec2) IsZero() bool

func (Vec2) Length

func (v Vec2) Length() float32

func (Vec2) SqrLength

func (v Vec2) SqrLength() float32

type Vec3

type Vec3 struct {
	X float32
	Y float32
	Z float32
}

func ArrayToVec3 added in v0.3.0

func ArrayToVec3(array [3]float32) Vec3

func BasisXVec3

func BasisXVec3() Vec3

func BasisYVec3

func BasisYVec3() Vec3

func BasisZVec3

func BasisZVec3() Vec3

func InverseVec3

func InverseVec3(vector Vec3) Vec3

func Mat3Vec3Prod

func Mat3Vec3Prod(mat Mat3, vec Vec3) Vec3

func Mat4Vec3Transformation

func Mat4Vec3Transformation(mat Mat4, vec Vec3) Vec3

func NewVec3

func NewVec3(x, y, z float32) Vec3

func NormalVec3 added in v0.7.0

func NormalVec3(vector Vec3) Vec3

func QuatVec3Rotation

func QuatVec3Rotation(q Quat, v Vec3) Vec3

func ResizedVec3

func ResizedVec3(vector Vec3, newLength float32) Vec3

func UnitVec3

func UnitVec3(vector Vec3) Vec3

func Vec3Cross

func Vec3Cross(a, b Vec3) Vec3

func Vec3Diff

func Vec3Diff(a, b Vec3) Vec3

func Vec3Lerp added in v0.4.0

func Vec3Lerp(a, b Vec3, t float32) Vec3

func Vec3MultiDiff added in v0.7.0

func Vec3MultiDiff(first Vec3, others ...Vec3) Vec3

func Vec3MultiSum added in v0.7.0

func Vec3MultiSum(first Vec3, others ...Vec3) Vec3

func Vec3Prod

func Vec3Prod(vector Vec3, value float32) Vec3

func Vec3Quot

func Vec3Quot(vector Vec3, value float32) Vec3

func Vec3Sum

func Vec3Sum(a, b Vec3) Vec3

func ZeroVec3

func ZeroVec3() Vec3

func (Vec3) Array added in v0.2.0

func (v Vec3) Array() [3]float32

func (Vec3) GoString

func (v Vec3) GoString() string

func (Vec3) IsInf added in v0.7.0

func (v Vec3) IsInf() bool

func (Vec3) IsNaN added in v0.7.0

func (v Vec3) IsNaN() bool

func (Vec3) IsZero

func (v Vec3) IsZero() bool

func (Vec3) Length

func (v Vec3) Length() float32

func (Vec3) SqrLength

func (v Vec3) SqrLength() float32

type Vec4

type Vec4 struct {
	X float32
	Y float32
	Z float32
	W float32
}

func ArrayToVec4 added in v0.3.0

func ArrayToVec4(array [4]float32) Vec4

func InverseVec4

func InverseVec4(vector Vec4) Vec4

func Mat4Vec4Prod

func Mat4Vec4Prod(mat Mat4, vec Vec4) Vec4

func NewVec4

func NewVec4(x, y, z, w float32) Vec4

func Vec4Diff

func Vec4Diff(a, b Vec4) Vec4

func Vec4Lerp added in v0.4.0

func Vec4Lerp(a, b Vec4, t float32) Vec4

func Vec4MultiDiff added in v0.7.0

func Vec4MultiDiff(first Vec4, others ...Vec4) Vec4

func Vec4MultiSum added in v0.7.0

func Vec4MultiSum(first Vec4, others ...Vec4) Vec4

func Vec4Prod

func Vec4Prod(vector Vec4, value float32) Vec4

func Vec4Quot

func Vec4Quot(vector Vec4, value float32) Vec4

func Vec4Sum

func Vec4Sum(a, b Vec4) Vec4

func ZeroVec4

func ZeroVec4() Vec4

func (Vec4) Array added in v0.2.0

func (v Vec4) Array() [4]float32

func (Vec4) GoString

func (v Vec4) GoString() string

func (Vec4) IsInf added in v0.7.0

func (v Vec4) IsInf() bool

func (Vec4) IsNaN added in v0.7.0

func (v Vec4) IsNaN() bool

func (Vec4) IsZero

func (v Vec4) IsZero() bool

func (Vec4) VecXYZ

func (v Vec4) VecXYZ() Vec3

Jump to

Keyboard shortcuts

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