Documentation ¶
Index ¶
- type Num
- type Vector2
- func (v Vector2[T]) Add(v2 Vector2[T]) Vector2[T]
- func (v Vector2[T]) AddX(x T) Vector2[T]
- func (v Vector2[T]) AddXY(x, y T) Vector2[T]
- func (v Vector2[T]) AddY(y T) Vector2[T]
- func (v Vector2[T]) Angle() float64
- func (v Vector2[T]) Apply(f func(T) T) Vector2[T]
- func (v Vector2[T]) Cross(v2 Vector2[T]) T
- func (v Vector2[T]) Distance(v2 Vector2[T]) float64
- func (v Vector2[T]) DivX(x T) Vector2[T]
- func (v Vector2[T]) DivXY(x, y T) Vector2[T]
- func (v Vector2[T]) DivY(y T) Vector2[T]
- func (v Vector2[T]) Dot(v2 Vector2[T]) T
- func (v Vector2[T]) InvScale(a T) Vector2[T]
- func (v Vector2[T]) Length() float64
- func (v Vector2[T]) Lerp(v2 Vector2[T], t T) Vector2[T]
- func (v Vector2[T]) Map(f func(T, T) (T, T)) Vector2[T]
- func (v Vector2[T]) MulX(x T) Vector2[T]
- func (v Vector2[T]) MulXY(x, y T) Vector2[T]
- func (v Vector2[T]) MulY(y T) Vector2[T]
- func (v Vector2[T]) Normalize() Vector2[T]
- func (v Vector2[T]) Project(v2 Vector2[T]) Vector2[T]
- func (v Vector2[T]) Reflect(v2 Vector2[T]) Vector2[T]
- func (v Vector2[T]) Rotate(angle float64) Vector2[T]
- func (v Vector2[T]) Scale(a T) Vector2[T]
- func (v Vector2[T]) String() string
- func (v Vector2[T]) Sub(v2 Vector2[T]) Vector2[T]
- func (v Vector2[T]) SubX(x T) Vector2[T]
- func (v Vector2[T]) SubXY(x, y T) Vector2[T]
- func (v Vector2[T]) SubY(y T) Vector2[T]
- func (v Vector2[T]) X() T
- func (v Vector2[T]) XY() (x, y T)
- func (v Vector2[T]) Y() T
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 MakeAtAngle ¶
MakeAtAngle returns a vector of type T with the given magnitude at the given angle in radians.
func (Vector2[T]) Add ¶
Add will add this and v2 together. A new vector with the result will be returned.
func (Vector2[T]) AddX ¶
AddX will add x into the x component. A new vector with the result will be returned.
func (Vector2[T]) AddXY ¶
AddXY will add x and y to their respective component. A new vector with the result will be returned.
func (Vector2[T]) AddY ¶
AddY will add y into the y component. A new vector with the result will be returned.
func (Vector2[T]) Angle ¶
Angle will calculate the angle of this off of the unit circle. The result will be returned in radians.
func (Vector2[T]) Apply ¶
Apply will apply a function to both components individually. A new vector with the result will be returned.
func (Vector2[T]) Cross ¶
Cross will multiply this by v2 using cross product multiplication. The result will be returned.
func (Vector2[T]) Distance ¶
Distance will calculate the distance from this to v2. The result will be returned.
func (Vector2[T]) DivX ¶
DivX will divide the x component by x. A new vector with the result will be returned.
func (Vector2[T]) DivXY ¶
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 ¶
DivY will divide the y component by y. A new vector with the result will be returned.
func (Vector2[T]) Dot ¶
Dot will multiply this by v2 using dot product multiplication. The result will be returned.
func (Vector2[T]) InvScale ¶
InvScale will divide this by a scalar. A new vector with the result will be returned.
func (Vector2[T]) Lerp ¶
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 ¶
Map will apply a function to both components together. A new vector with the result will be returned.
func (Vector2[T]) MulX ¶
MulX will multiply the x component by x. A new vector with the result will be returned.
func (Vector2[T]) MulXY ¶
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 ¶
MulY will multiply the y component by y. A new vector with the result will be returned.
func (Vector2[T]) Normalize ¶
Normalize will calculate the unit vector for this. A new vector with the result will be returned.
func (Vector2[T]) Project ¶
Project will project this onto v2. A new vector with the result will be returned.
func (Vector2[T]) Reflect ¶
Reflect will reflect this over v2. A new vector with the vv2esult will be returned.
func (Vector2[T]) Rotate ¶
Rotate will rotate this around the unit circle by angle radians. A new vector with the result will be returned.
func (Vector2[T]) Scale ¶
Scale will multiply this by a scalar. A new vector with the result will be returned.
func (Vector2[T]) Sub ¶
Sub will subtract v2 from this. A new vector with the result will be returned.
func (Vector2[T]) SubX ¶
SubX will subtract x from the x component. A new vector with the result will be returned.
func (Vector2[T]) SubXY ¶
SubXY will subtract x and y from their respective component. A new vector with the result will be returned.