vector2

package
v0.0.0-...-c567865 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Num

type Num interface {
	constraints.Integer | constraints.Float
}

Num represents any real number type. Use this to make generic functions that return generic Vector2s.

type Vector2

type Vector2[T Num] struct {
	// contains filtered or unexported fields
}

Vector2 represents an immutable 2D vector of any real number type.

func Make

func Make[T Num](x, y T) Vector2[T]

Make returns a vector of type T with components x and y.

func MakeAtAngle

func MakeAtAngle[T Num](magnitude, angle float64) Vector2[T]

MakeAtAngle returns a vector of type T with the given magnitude at the given angle in radians.

func To

func To[T, E Num](v Vector2[E]) Vector2[T]

To returns the result of casting a vector of type E to type T.

func (Vector2[T]) Add

func (v Vector2[T]) Add(v2 Vector2[T]) Vector2[T]

Add will add this and v2 together. A new vector with the result will be returned.

func (Vector2[T]) AddX

func (v Vector2[T]) AddX(x T) Vector2[T]

AddX will add x into the x component. A new vector with the result will be returned.

func (Vector2[T]) AddXY

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

AddXY will add x and y to their respective component. A new vector with the result will be returned.

func (Vector2[T]) AddY

func (v Vector2[T]) AddY(y T) Vector2[T]

AddY will add y into the y component. A new vector with the result will be returned.

func (Vector2[T]) Angle

func (v Vector2[T]) Angle() float64

Angle will calculate the angle of this off of the unit circle. The result will be returned in radians.

func (Vector2[T]) Apply

func (v Vector2[T]) Apply(f func(T) T) Vector2[T]

Apply will apply a function to both components individually. A new vector with the result will be returned.

func (Vector2[T]) Cross

func (v Vector2[T]) Cross(v2 Vector2[T]) T

Cross will multiply this by v2 using cross product multiplication. The result will be returned.

func (Vector2[T]) Distance

func (v Vector2[T]) Distance(v2 Vector2[T]) float64

Distance will calculate the distance from this to v2. The result will be returned.

func (Vector2[T]) DivX

func (v Vector2[T]) DivX(x T) Vector2[T]

DivX will divide the x component by x. A new vector with the result will be returned.

func (Vector2[T]) DivXY

func (v Vector2[T]) DivXY(x, y T) Vector2[T]

DivXY will divide the x and y components by their respective parameter. A new vector with the result will be returned.

func (Vector2[T]) DivY

func (v Vector2[T]) DivY(y T) Vector2[T]

DivY will divide the y component by y. A new vector with the result will be returned.

func (Vector2[T]) Dot

func (v Vector2[T]) Dot(v2 Vector2[T]) T

Dot will multiply this by v2 using dot product multiplication. The result will be returned.

func (Vector2[T]) InvScale

func (v Vector2[T]) InvScale(a T) Vector2[T]

InvScale will divide this by a scalar. A new vector with the result will be returned.

func (Vector2[T]) Length

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

Length will calculate the length of this. The result will be returned.

func (Vector2[T]) Lerp

func (v Vector2[T]) Lerp(v2 Vector2[T], t T) Vector2[T]

Lerp will perform linear interpolation between this and v2 using factor t. A new vector with the result will be returned.

func (Vector2[T]) Map

func (v Vector2[T]) Map(f func(T, T) (T, T)) Vector2[T]

Map will apply a function to both components together. A new vector with the result will be returned.

func (Vector2[T]) MulX

func (v Vector2[T]) MulX(x T) Vector2[T]

MulX will multiply the x component by x. A new vector with the result will be returned.

func (Vector2[T]) MulXY

func (v Vector2[T]) MulXY(x, y T) Vector2[T]

MulXY will multiply the x and y components by their respective parameter. A new vector with the result will be returned.

func (Vector2[T]) MulY

func (v Vector2[T]) MulY(y T) Vector2[T]

MulY will multiply the y component by y. A new vector with the result will be returned.

func (Vector2[T]) Normalize

func (v Vector2[T]) Normalize() Vector2[T]

Normalize will calculate the unit vector for this. A new vector with the result will be returned.

func (Vector2[T]) Project

func (v Vector2[T]) Project(v2 Vector2[T]) Vector2[T]

Project will project this onto v2. A new vector with the result will be returned.

func (Vector2[T]) Reflect

func (v Vector2[T]) Reflect(v2 Vector2[T]) Vector2[T]

Reflect will reflect this over v2. A new vector with the vv2esult will be returned.

func (Vector2[T]) Rotate

func (v Vector2[T]) Rotate(angle float64) Vector2[T]

Rotate will rotate this around the unit circle by angle radians. A new vector with the result will be returned.

func (Vector2[T]) Scale

func (v Vector2[T]) Scale(a T) Vector2[T]

Scale will multiply this by a scalar. A new vector with the result will be returned.

func (Vector2[T]) String

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

String will return the vector formatted as a string.

func (Vector2[T]) Sub

func (v Vector2[T]) Sub(v2 Vector2[T]) Vector2[T]

Sub will subtract v2 from this. A new vector with the result will be returned.

func (Vector2[T]) SubX

func (v Vector2[T]) SubX(x T) Vector2[T]

SubX will subtract x from the x component. A new vector with the result will be returned.

func (Vector2[T]) SubXY

func (v Vector2[T]) SubXY(x, y T) Vector2[T]

SubXY will subtract x and y from their respective component. A new vector with the result will be returned.

func (Vector2[T]) SubY

func (v Vector2[T]) SubY(y T) Vector2[T]

SubY will subtract y from the y component. A new vector with the result will be returned.

func (Vector2[T]) X

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

X returns the x component.

func (Vector2[T]) XY

func (v Vector2[T]) XY() (x, y T)

XY returns both the x and y component.

func (Vector2[T]) Y

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

Y returns the y component.

Jump to

Keyboard shortcuts

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