vector4

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare[T mathex.SignedNumber](a, b Of[T]) int

func MaxW

func MaxW[T mathex.SignedNumber](a, b Of[T]) T

func MaxX

func MaxX[T mathex.SignedNumber](a, b Of[T]) T

func MaxY

func MaxY[T mathex.SignedNumber](a, b Of[T]) T

func MaxZ

func MaxZ[T mathex.SignedNumber](a, b Of[T]) T

func MinW

func MinW[T mathex.SignedNumber](a, b Of[T]) T

func MinX

func MinX[T mathex.SignedNumber](a, b Of[T]) T

func MinY

func MinY[T mathex.SignedNumber](a, b Of[T]) T

func MinZ

func MinZ[T mathex.SignedNumber](a, b Of[T]) T

Types

type Float32

type Float32 = Of[float32]

func NewFloat32

func NewFloat32[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Float32

type Float64

type Float64 = Of[float64]

func FromColor

func FromColor(c color.Color) Float64

func NewFloat64

func NewFloat64[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Float64

type Int

type Int = Of[int]

func NewInt

func NewInt[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Int

type Int8

type Int8 = Of[int8]

func NewInt8

func NewInt8[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Int8

type Int16

type Int16 = Of[int16]

func NewInt16

func NewInt16[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Int16

type Int32

type Int32 = Of[int32]

func NewInt32

func NewInt32[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Int32

type Int64

type Int64 = Of[int64]

func NewInt64

func NewInt64[XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Int64

type Of

type Of[T mathex.SignedNumber] struct {
	X T
	Y T
	Z T
	W T
}

Of contains 4 components

func Average

func Average[T mathex.SignedNumber](vectors []Of[T]) Of[T]

Average sums all vector4's components together and divides each component by the number of vectors added

func Fill

func Fill[T mathex.SignedNumber](v T) Of[T]

Fill creates a vector where each component is equal to v

func FromArray

func FromArray[T mathex.SignedNumber](data []T) Of[T]

Builds a vector from the data found from the passed in array to the best of it's ability. If the length of the array is smaller than the vector itself, only those values will be used to build the vector, and the remaining vector components will remain the default value of the vector's data type (some version of 0).

func Lerp

func Lerp[T mathex.SignedNumber](a, b Of[T], t float64) Of[T]

Lerp linearly interpolates between a and b by t

func Max

func Max[T mathex.SignedNumber](a, b Of[T]) Of[T]

func Midpoint

func Midpoint[T mathex.SignedNumber](a, b Of[T]) Of[T]

func Min

func Min[T mathex.SignedNumber](a, b Of[T]) Of[T]

func New

func New[T mathex.SignedNumber](x, y, z, w T) Of[T]

New creates a new vector with corresponding 3 components

func NewT

func NewT[T mathex.SignedNumber, XT, YT, ZT, WT mathex.Number](x XT, y YT, z ZT, w WT) Of[T]

func One

func One[T mathex.SignedNumber]() Of[T]

One is (1, 1, 1)

func Read

func Read[T mathex.SignedNumber](in io.Reader, endian binary.ByteOrder) (v Of[T], err error)

func ReadFloat32

func ReadFloat32(in io.Reader, endian binary.ByteOrder) (Of[float32], error)

func ReadFloat64

func ReadFloat64(in io.Reader, endian binary.ByteOrder) (Of[float64], error)

func ReadInt8

func ReadInt8(in io.Reader) (Of[int8], error)

func ReadInt16

func ReadInt16(in io.Reader, endian binary.ByteOrder) (Of[int16], error)

func ReadInt32

func ReadInt32(in io.Reader, endian binary.ByteOrder) (Of[int32], error)

func ReadInt64

func ReadInt64(in io.Reader, endian binary.ByteOrder) (Of[int64], error)

func To

func To[T, OT mathex.SignedNumber](v Of[OT]) Of[T]

func Zero

func Zero[T mathex.SignedNumber]() Of[T]

Zero is (0, 0, 0)

func (Of[T]) Abs

func (v Of[T]) Abs() Of[T]

Abs applies the Abs math operation to each component of the vector

func (Of[T]) Add

func (v Of[T]) Add(other Of[T]) Of[T]

Add takes each component of our vector and adds them to the vector passed in, returning a resulting vector

func (Of[T]) AddW

func (v Of[T]) AddW(dW T) Of[T]

func (Of[T]) AddX

func (v Of[T]) AddX(dX T) Of[T]

func (Of[T]) AddY

func (v Of[T]) AddY(dY T) Of[T]

func (Of[T]) AddZ

func (v Of[T]) AddZ(dZ T) Of[T]

func (Of[T]) Ceil

func (v Of[T]) Ceil() Of[T]

Ceil applies the ceil math operation to each component of the vector

func (Of[T]) CeilToInt

func (v Of[T]) CeilToInt() Of[int]

CeilToInt applies the ceil math operation to each component of the vector, and then casts it to a int

func (Of[T]) Clamp

func (v Of[T]) Clamp(vmin, vmax T) Of[T]

func (Of[T]) ContainsNaN

func (v Of[T]) ContainsNaN() bool

func (Of[T]) DivByConstant

func (v Of[T]) DivByConstant(t float64) Of[T]

func (Of[T]) Dot

func (v Of[T]) Dot(other Of[T]) float64

func (Of[T]) Exp

func (v Of[T]) Exp() Of[T]

Exp returns e**x, the base-e exponential for each component

func (Of[T]) Exp2

func (v Of[T]) Exp2() Of[T]

Exp2 returns 2**x, the base-2 exponential for each component

func (Of[T]) Expm1

func (v Of[T]) Expm1() Of[T]

Expm1 returns e**x - 1, the base-e exponential for each component minus 1. It is more accurate than Exp(x) - 1 when the component is near zero

func (Of[T]) Flip

func (v Of[T]) Flip() Of[T]

func (Of[T]) FlipW

func (v Of[T]) FlipW() Of[T]

func (Of[T]) FlipX

func (v Of[T]) FlipX() Of[T]

func (Of[T]) FlipY

func (v Of[T]) FlipY() Of[T]

func (Of[T]) FlipZ

func (v Of[T]) FlipZ() Of[T]

func (Of[T]) Floor

func (v Of[T]) Floor() Of[T]

Floor applies the floor math operation to each component of the vector

func (Of[T]) FloorToInt

func (v Of[T]) FloorToInt() Of[int]

FloorToInt applies the floor math operation to each component of the vector, and then casts it to a int

func (Of[T]) Format

func (v Of[T]) Format(format string) string

func (Of[T]) Length

func (v Of[T]) Length() float64

func (Of[T]) LengthF

func (v Of[T]) LengthF() float32

func (Of[T]) LengthSquared

func (v Of[T]) LengthSquared() T

func (Of[T]) Log

func (v Of[T]) Log() Of[T]

Log returns the natural logarithm for each component

func (Of[T]) Log2

func (v Of[T]) Log2() Of[T]

Log2 returns the binary logarithm for each component

func (Of[T]) Log10

func (v Of[T]) Log10() Of[T]

Log10 returns the decimal logarithm for each component.

func (Of[T]) MarshalJSON

func (v Of[T]) MarshalJSON() ([]byte, error)

func (Of[T]) MaxComponent

func (v Of[T]) MaxComponent() T

func (Of[T]) MinComponent

func (v Of[T]) MinComponent() T

func (Of[T]) MultByVector

func (v Of[T]) MultByVector(o Of[T]) Of[T]

MultByVector is component wise multiplication, also known as Hadamard product.

func (Of[T]) NearZero

func (v Of[T]) NearZero() bool

func (Of[T]) Negated

func (v Of[T]) Negated() Of[T]

func (Of[T]) Normalized

func (v Of[T]) Normalized() Of[T]

func (Of[T]) Product

func (v Of[T]) Product() T

func (Of[T]) Reciprocal

func (v Of[T]) Reciprocal() Of[float64]

func (Of[T]) ReciprocalF

func (v Of[T]) ReciprocalF() Of[float32]

func (Of[T]) Round

func (v Of[T]) Round() Of[T]

Round takes each component of the vector and rounds it to the nearest whole number

func (Of[T]) RoundToInt

func (v Of[T]) RoundToInt() Of[int]

RoundToInt takes each component of the vector and rounds it to the nearest whole number, and then casts it to a int

func (Of[T]) Scale

func (v Of[T]) Scale(t float64) Of[T]

func (Of[T]) SetW

func (v Of[T]) SetW(newW T) Of[T]

SetW changes the w component of the vector

func (Of[T]) SetX

func (v Of[T]) SetX(newX T) Of[T]

SetX changes the x component of the vector

func (Of[T]) SetY

func (v Of[T]) SetY(newY T) Of[T]

SetY changes the y component of the vector

func (Of[T]) SetZ

func (v Of[T]) SetZ(newZ T) Of[T]

SetZ changes the z component of the vector

func (Of[T]) Sqrt

func (v Of[T]) Sqrt() Of[T]

Sqrt applies the Sqrt to each component of the vector

func (Of[T]) String

func (v Of[T]) String() string

func (Of[T]) Sub

func (v Of[T]) Sub(other Of[T]) Of[T]

func (Of[T]) ToFloat32

func (v Of[T]) ToFloat32() Of[float32]

func (Of[T]) ToFloat64

func (v Of[T]) ToFloat64() Of[float64]

func (Of[T]) ToInt

func (v Of[T]) ToInt() Of[int]

func (Of[T]) ToInt8

func (v Of[T]) ToInt8() Of[int8]

func (Of[T]) ToInt16

func (v Of[T]) ToInt16() Of[int16]

func (Of[T]) ToInt32

func (v Of[T]) ToInt32() Of[int32]

func (Of[T]) ToInt64

func (v Of[T]) ToInt64() Of[int64]

func (*Of[T]) UnmarshalJSON

func (v *Of[T]) UnmarshalJSON(data []byte) error

func (Of[T]) Values

func (v Of[T]) Values() (T, T, T, T)

func (Of[T]) Write

func (v Of[T]) Write(out io.Writer, endian binary.ByteOrder) (err error)

func (Of[T]) XY

func (v Of[T]) XY() vector2.Of[T]

XY returns vector2 with the x and y components

func (Of[T]) XYZ

func (v Of[T]) XYZ() vector3.Of[T]

func (Of[T]) XZ

func (v Of[T]) XZ() vector2.Of[T]

XZ returns vector2 with the x and z components

func (Of[T]) YX

func (v Of[T]) YX() vector2.Of[T]

YX returns vector2 with the y and x components

func (Of[T]) YZ

func (v Of[T]) YZ() vector2.Of[T]

YZ returns vector2 with the y and z components

func (Of[T]) ZX

func (v Of[T]) ZX() vector2.Of[T]

ZX returns vector2 with the z and x components

func (Of[T]) ZY

func (v Of[T]) ZY() vector2.Of[T]

ZY returns vector2 with the z and y components

Jump to

Keyboard shortcuts

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