vector2

package
v0.0.0-...-b402d3d Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

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

func Greater

func Greater[T mathex.SignedNumber](a, b Vector[T]) bool

func GreaterEq

func GreaterEq[T mathex.SignedNumber](a, b Vector[T]) bool

func Less

func Less[T mathex.SignedNumber](a, b Vector[T]) bool

func LessEq

func LessEq[T mathex.SignedNumber](a, b Vector[T]) bool

func MaxX

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

func MaxY

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

func MinX

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

func MinY

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

Types

type Float32

type Float32 = Vector[float32]

func NewFloat32

func NewFloat32[XT, YT mathex.Number](x XT, y YT) Float32

type Float64

type Float64 = Vector[float64]

func NewFloat64

func NewFloat64[XT, YT mathex.Number](x XT, y YT) Float64

type Int

type Int = Vector[int]

func Index

func Index(xy Int, i int) Int

func NewInt

func NewInt[XT, YT mathex.Number](x XT, y YT) Int

type Int16

type Int16 = Vector[int16]

func NewInt16

func NewInt16[XT, YT mathex.Number](x XT, y YT) Int16

type Int32

type Int32 = Vector[int32]

func NewInt32

func NewInt32[XT, YT mathex.Number](x XT, y YT) Int32

type Int64

type Int64 = Vector[int64]

func NewInt64

func NewInt64[XT, YT mathex.Number](x XT, y YT) Int64

type Int8

type Int8 = Vector[int8]

func NewInt8

func NewInt8[XT, YT mathex.Number](x XT, y YT) Int8

type Vector

type Vector[T mathex.SignedNumber] struct {
	X T
	Y T
}

func Down

func Down[T mathex.SignedNumber]() Vector[T]

func Fill

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

Fill creates a vector where each component is equal to v

func FromArray

func FromArray[T mathex.SignedNumber](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 Left

func Left[T mathex.SignedNumber]() Vector[T]

func Lerp

func Lerp[T mathex.SignedNumber](t float32, a, b Vector[T]) Vector[T]

Lerp linearly interpolates between a and b by t

func Max

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

func Midpoint

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

func Min

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

func New

func New[T mathex.SignedNumber](x T, y T) Vector[T]

func NewT

func NewT[T mathex.SignedNumber, XT, YT mathex.Number](x XT, y YT) Vector[T]

func One

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

func Rand

func Rand(r *rand.Rand) Vector[float64]

func Read

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

func ReadFloat32

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

func ReadFloat64

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

func ReadInt16

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

func ReadInt32

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

func ReadInt64

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

func ReadInt8

func ReadInt8(in io.Reader) (Vector[int8], error)
func Right[T mathex.SignedNumber]() Vector[T]

func To

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

func Up

func Up[T mathex.SignedNumber]() Vector[T]

func Zero

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

func (Vector[T]) Abs

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 returns a vector that is the result of two vectors added together

func (Vector[T]) AddX

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

AddX adds to the x component of the vector

func (Vector[T]) AddXY

func (v Vector[T]) AddXY(x, y T) Vector[T]

func (Vector[T]) AddY

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

AddY adds to the y component of the vector

func (Vector[T]) Angle

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

Angle return angle in radians between vector and other vector [float64]

func (Vector[T]) AngleF

func (v Vector[T]) AngleF(other Vector[T]) float32

AngleF return angle in radians between vector and other vector [float32]

func (Vector[T]) Axis

func (v Vector[T]) Axis(i Axis) T

func (Vector[T]) Ceil

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

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

func (Vector[T]) CeilToInt

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

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

func (Vector[T]) Clamp0V

func (v Vector[T]) Clamp0V(vmax Vector[T]) Vector[T]

func (Vector[T]) ClampV

func (v Vector[T]) ClampV(vmin, vmax Vector[T]) Vector[T]

func (Vector[T]) ContainsNaN

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

func (Vector[T]) Cross

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

Cross return cross product between vector and other vector

func (Vector[T]) CrossV

func (v Vector[T]) CrossV(value T) Vector[T]

Cross return cross product between vector and value

func (Vector[T]) Distance

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

Distance is the euclidean distance between two points

func (Vector[T]) DistanceSquared

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

func (Vector[T]) DivByConstant

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

func (Vector[T]) DivByVector

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

func (Vector[T]) Dot

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

Dot return dot product between vector and other vector

func (Vector[T]) EnumRegion

func (v Vector[T]) EnumRegion(w, h T, step ...T) iter.Seq[Vector[T]]

func (Vector[T]) EnumRegionAround

func (v Vector[T]) EnumRegionAround(w, h T, step ...T) iter.Seq[Vector[T]]

func (Vector[T]) Exp

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

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

func (Vector[T]) Exp2

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

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

func (Vector[T]) Expm1

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

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

func (Vector[T]) FlipX

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

func (Vector[T]) FlipY

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

func (Vector[T]) Floor

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

func (Vector[T]) FloorToInt

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

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

func (Vector[T]) Inv

func (v Vector[T]) Inv() Float64

func (Vector[T]) InvF

func (v Vector[T]) InvF() Float32

func (Vector[T]) IsZero

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

func (Vector[T]) Length

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

func (Vector[T]) LengthF

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

func (Vector[T]) LengthSquared

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

func (Vector[T]) Log

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

Log returns the natural logarithm for each component

func (Vector[T]) Log10

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

Log10 returns the decimal logarithm for each component.

func (Vector[T]) Log2

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

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

func (Vector[T]) Midpoint

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

Midpoint returns the midpoint between this vector and the vector passed in.

func (Vector[T]) MinComponent

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

func (Vector[T]) MultByVector

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

func (Vector[T]) NearZero

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

func (Vector[T]) NearZeroF

func (v Vector[T]) NearZeroF(epsilon float32) bool

func (Vector[T]) Negated

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

func (Vector[T]) Normalize

func (v Vector[T]) Normalize(a Vector[T]) Float64

func (Vector[T]) NormalizeF

func (v Vector[T]) NormalizeF(a Vector[T]) Float32

func (Vector[T]) Normalized

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

func (Vector[T]) Perpendicular

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

Perpendicular creates a vector perpendicular to the one passed in with the same magnitude

func (Vector[T]) Pivot

func (v Vector[T]) Pivot(anchor Vector[T], wh Vector[T]) Vector[T]

func (Vector[T]) Product

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

func (Vector[T]) Project

func (v Vector[T]) Project(normal Vector[T]) Vector[T]

func (Vector[T]) Reciprocal

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

func (Vector[T]) ReciprocalF

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

func (Vector[T]) Reflect

func (v Vector[T]) Reflect(normal Vector[T]) Vector[T]

func (Vector[T]) Reject

func (v Vector[T]) Reject(normal Vector[T]) Vector[T]

func (Vector[T]) Round

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

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]) RoundToVector

func (v Vector[T]) RoundToVector(scale Vector[T]) Vector[T]

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]) ScaleByVector

func (v Vector[T]) ScaleByVector(o Float64) Vector[T]

func (Vector[T]) ScaleByVectorF

func (v Vector[T]) ScaleByVectorF(o Float32) Vector[T]

func (Vector[T]) ScaleByVectorI

func (v Vector[T]) ScaleByVectorI(o Int) Vector[T]

func (Vector[T]) ScaleByXY

func (v Vector[T]) ScaleByXY(x, y float64) Vector[T]

func (Vector[T]) ScaleByXYF

func (v Vector[T]) ScaleByXYF(x, y float32) Vector[T]

func (Vector[T]) ScaleByXYI

func (v Vector[T]) ScaleByXYI(x, y int) Vector[T]

func (Vector[T]) ScaleF

func (v Vector[T]) ScaleF(t float32) Vector[T]

func (Vector[T]) SetAxis

func (v Vector[T]) SetAxis(i Axis, a T) Vector[T]

func (Vector[T]) SetX

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

SetX changes the x component of the vector

func (Vector[T]) SetY

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

SetY changes the y component of the vector

func (Vector[T]) SignI

func (v Vector[T]) SignI() Int

func (Vector[T]) Sqrt

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

Sqrt applies the Sqrt to each component of the vector

func (Vector[T]) String

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

func (Vector[T]) Sub

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

func (Vector[T]) SubXY

func (v Vector[T]) SubXY(x, y T) Vector[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]) ToInt16

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

func (Vector[T]) ToInt32

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

func (Vector[T]) ToInt64

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

func (Vector[T]) ToInt8

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

func (Vector[T]) ToNpot

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

func (*Vector[T]) UnmarshalJSON

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

func (Vector[T]) Values

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

func (Vector[T]) Write

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

func (Vector[T]) YX

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

func (Vector[T]) ZeroF

func (v Vector[T]) ZeroF(epsilon float32) Float32

Jump to

Keyboard shortcuts

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