vector4

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 9 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxW added in v1.6.0

func MaxW[T vector.Number](a, b Vector[T]) T

func MaxX added in v1.6.0

func MaxX[T vector.Number](a, b Vector[T]) T

func MaxY added in v1.6.0

func MaxY[T vector.Number](a, b Vector[T]) T

func MaxZ added in v1.6.0

func MaxZ[T vector.Number](a, b Vector[T]) T

func MinW added in v1.6.0

func MinW[T vector.Number](a, b Vector[T]) T

func MinX added in v1.6.0

func MinX[T vector.Number](a, b Vector[T]) T

func MinY added in v1.6.0

func MinY[T vector.Number](a, b Vector[T]) T

func MinZ added in v1.6.0

func MinZ[T vector.Number](a, b Vector[T]) T

Types

type Float32

type Float32 = Vector[float32]

type Float64

type Float64 = Vector[float64]

func FromColor added in v1.1.0

func FromColor(c color.Color) Float64

type Int

type Int = Vector[int]

type Int16 added in v1.2.0

type Int16 = Vector[int16]

type Int32 added in v1.2.0

type Int32 = Vector[int32]

type Int64

type Int64 = Vector[int64]

type Int8 added in v1.2.0

type Int8 = Vector[int8]

type Serializable added in v1.7.0

type Serializable[T vector.Number] struct {
	X T
	Y T
	Z T
	W T
}

func (Serializable[T]) Immutable added in v1.7.0

func (m Serializable[T]) Immutable() Vector[T]

type Space added in v1.11.0

type Space[T vector.Number] struct{}

func (Space[T]) Add added in v1.11.0

func (Space[T]) Add(a, b Vector[T]) Vector[T]

func (Space[T]) Distance added in v1.11.0

func (Space[T]) Distance(a, b Vector[T]) float64

func (Space[T]) Dot added in v1.11.0

func (Space[T]) Dot(a, b Vector[T]) float64

func (Space[T]) Length added in v1.11.0

func (Space[T]) Length(a Vector[T]) float64

func (Space[T]) Lerp added in v1.11.0

func (Space[T]) Lerp(a, b Vector[T], time float64) Vector[T]

func (Space[T]) Normalized added in v1.11.0

func (Space[T]) Normalized(a Vector[T]) Vector[T]

func (Space[T]) Scale added in v1.11.0

func (Space[T]) Scale(a Vector[T], amount float64) Vector[T]

func (Space[T]) Sub added in v1.11.0

func (Space[T]) Sub(a, b Vector[T]) Vector[T]

type Vector

type Vector[T vector.Number] struct {
	// contains filtered or unexported fields
}

Vector contains 4 components

func Average

func Average[T vector.Number](vectors []Vector[T]) Vector[T]

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

func Fill added in v1.1.0

func Fill[T vector.Number](v T) Vector[T]

Fill creates a vector where each component is equal to v

func FromArray added in v1.1.0

func FromArray[T vector.Number](data []T) Vector[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 vector.Number](a, b Vector[T], t float64) Vector[T]

Lerp linearly interpolates between a and b by t

func LerpClamped added in v1.8.0

func LerpClamped[T vector.Number](a, b Vector[T], t float64) Vector[T]

func Max

func Max[T vector.Number](a, b Vector[T]) Vector[T]

func Midpoint added in v1.1.0

func Midpoint[T vector.Number](a, b Vector[T]) Vector[T]

func Min

func Min[T vector.Number](a, b Vector[T]) Vector[T]

func New

func New[T vector.Number](x, y, z, w T) Vector[T]

New creates a new vector with corresponding 3 components

func One

func One[T vector.Number]() Vector[T]

One is (1, 1, 1)

func Read added in v1.7.0

func Read[T vector.Number](in io.Reader, endian binary.ByteOrder) (v Vector[T], err error)

func ReadFloat32 added in v1.7.0

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

func ReadFloat64 added in v1.7.0

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

func ReadInt16 added in v1.7.0

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

func ReadInt32 added in v1.7.0

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

func ReadInt64 added in v1.7.0

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

func ReadInt8 added in v1.7.0

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

func Zero

func Zero[T vector.Number]() Vector[T]

Zero is (0, 0, 0)

func (Vector[T]) Abs added in v1.1.0

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

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

func (Vector[T]) Add

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

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

func (Vector[T]) AddW added in v1.12.0

func (v Vector[T]) AddW(other T) Vector[T]

func (Vector[T]) AddX added in v1.12.0

func (v Vector[T]) AddX(other T) Vector[T]

func (Vector[T]) AddY added in v1.12.0

func (v Vector[T]) AddY(other T) Vector[T]

func (Vector[T]) AddZ added in v1.12.0

func (v Vector[T]) AddZ(other T) Vector[T]

func (Vector[T]) Ceil added in v1.1.0

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

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

func (Vector[T]) CeilToInt added in v1.1.0

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

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

func (Vector[T]) Clamp added in v1.1.0

func (v Vector[T]) Clamp(min, max T) Vector[T]

func (Vector[T]) Component added in v1.7.0

func (v Vector[T]) Component(index int) T

func (Vector[T]) ContainsNaN added in v1.3.0

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

func (Vector[T]) Distance added in v1.11.0

func (v Vector[T]) Distance(other Vector[T]) float64

func (Vector[T]) DistanceSquared added in v1.11.0

func (v Vector[T]) DistanceSquared(other Vector[T]) float64

func (Vector[T]) DivByConstant

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

func (Vector[T]) DivByVector added in v1.10.0

func (v Vector[T]) DivByVector(o Vector[T]) Vector[T]

func (Vector[T]) Dot

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

func (Vector[T]) Exp added in v1.6.0

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

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

func (Vector[T]) Exp2 added in v1.6.0

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

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

func (Vector[T]) Expm1 added in v1.6.0

func (v Vector[T]) Expm1() Vector[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 (Vector[T]) Flip added in v1.4.0

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

func (Vector[T]) FlipW added in v1.4.0

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

func (Vector[T]) FlipX added in v1.4.0

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

func (Vector[T]) FlipY added in v1.4.0

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

func (Vector[T]) FlipZ added in v1.4.0

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

func (Vector[T]) Floor added in v1.1.0

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

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

func (Vector[T]) FloorToInt added in v1.1.0

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

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

func (Vector[T]) Format added in v1.3.0

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

func (Vector[T]) Fract added in v1.12.0

func (v Vector[T]) Fract() Vector[T]

Fract returns the fractional part of each component of the vector. This is calculated as x - floor(x).

func (Vector[T]) Length added in v1.5.0

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

func (Vector[T]) LengthSquared added in v1.5.0

func (v Vector[T]) LengthSquared() float64

func (Vector[T]) Log added in v1.6.0

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

Log returns the natural logarithm for each component

func (Vector[T]) Log10 added in v1.6.0

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

Log10 returns the decimal logarithm for each component.

func (Vector[T]) Log2 added in v1.6.0

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

Log2 returns the binary logarithm for each component

func (Vector[T]) MarshalJSON

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

func (Vector[T]) MaxComponent added in v1.2.0

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

func (Vector[T]) MinComponent added in v1.2.0

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

func (Vector[T]) Mod added in v1.9.0

func (v Vector[T]) Mod(t float64) Vector[T]

func (Vector[T]) MultByVector added in v1.1.0

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

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

func (Vector[T]) NearZero added in v1.6.0

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

func (Vector[T]) Normalized added in v1.5.0

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

func (Vector[T]) Round added in v1.1.0

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

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

func (Vector[T]) RoundToInt added in v1.1.0

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

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

func (Vector[T]) Scale

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

func (Vector[T]) SetW

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

SetW changes the w component of the vector

func (Vector[T]) SetX

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

SetX changes the x component of the vector

func (Vector[T]) SetY

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

SetY changes the y component of the vector

func (Vector[T]) SetZ

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

SetZ changes the z component of the vector

func (Vector[T]) Sqrt added in v1.1.0

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

Sqrt applies the math.Sqrt to each component of the vector

func (Vector[T]) Sub

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

func (Vector[T]) ToArr added in v1.8.0

func (v Vector[T]) ToArr() []T

func (Vector[T]) ToFixedArr added in v1.8.0

func (v Vector[T]) ToFixedArr() [4]T

func (Vector[T]) ToFloat32

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

func (Vector[T]) ToFloat64

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

func (Vector[T]) ToInt

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

func (Vector[T]) ToInt64

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

func (*Vector[T]) UnmarshalJSON

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

func (Vector[T]) Values added in v1.7.0

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

func (Vector[T]) W

func (v Vector[T]) W() T

W returns the w component

func (Vector[T]) Write added in v1.7.0

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

func (Vector[T]) X

func (v Vector[T]) X() T

X returns the x component

func (Vector[T]) XY added in v1.6.0

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

XY returns vector2 with the x and y components

func (Vector[T]) XYZ added in v1.6.0

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

func (Vector[T]) XZ added in v1.6.0

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

XZ returns vector2 with the x and z components

func (Vector[T]) Y

func (v Vector[T]) Y() T

Y returns the y component

func (Vector[T]) YX added in v1.6.0

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

YX returns vector2 with the y and x components

func (Vector[T]) YZ added in v1.6.0

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

YZ returns vector2 with the y and z components

func (Vector[T]) Z

func (v Vector[T]) Z() T

Z returns the z component

func (Vector[T]) ZX added in v1.6.0

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

ZX returns vector2 with the z and x components

func (Vector[T]) ZY added in v1.6.0

func (v Vector[T]) ZY() vector2.Vector[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