vector2

package
v0.0.0-...-e7326f8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Null     = New(0, 0)   // Vector2(0, 0)
	Right    = New(1, 0)   // Vector2(1, 0)
	Left     = New(-1, 0)  // Vector2(-1, 0)
	Up       = New(0, -1)  // Vector2(0, -1)
	Down     = New(0, 1)   // Vector2(0, 1)
	Identity = New(1, 1)   // Vector2(1, 1)
	Negative = New(-1, -1) // Vector2(-1, -1)
)

Functions

This section is empty.

Types

type Vector2

type Vector2 struct {
	X, Y float64
}

func New

func New(x, y float64) *Vector2

func NewB2

func NewB2(b2v box2d.B2Vec2) *Vector2

func NewInt

func NewInt(x, y int) *Vector2

func (*Vector2) Add

func (v *Vector2) Add(other *Vector2) *Vector2

func (*Vector2) AddScalar

func (v *Vector2) AddScalar(scalar float64) *Vector2

func (*Vector2) AddScalars

func (v *Vector2) AddScalars(x, y float64) *Vector2

func (*Vector2) AsB2

func (v *Vector2) AsB2() box2d.B2Vec2

Converts vector to the Box2D vector

func (*Vector2) AsTuple

func (v *Vector2) AsTuple() (x, y float64)

Returns the tuple (x, y float64)

func (*Vector2) Copy

func (v *Vector2) Copy() *Vector2

func (*Vector2) Distance

func (v *Vector2) Distance(other *Vector2) float64

Returns the distance between a and b.

func (*Vector2) Div

func (v *Vector2) Div(other *Vector2) *Vector2

func (*Vector2) DivScalar

func (v *Vector2) DivScalar(scalar float64) *Vector2

func (*Vector2) DivScalars

func (v *Vector2) DivScalars(x, y float64) *Vector2

Divide vector coordinates by the given values.

func (*Vector2) Dot

func (v *Vector2) Dot(other *Vector2) float64

Returns dot Product of two vectors.

func (*Vector2) Equals

func (v *Vector2) Equals(other *Vector2) bool

Checks whether the vectors are equal.

func (*Vector2) Greater

func (v *Vector2) Greater(other *Vector2) bool

Checks whether this vector is greater than other.

func (*Vector2) GreaterEq

func (v *Vector2) GreaterEq(other *Vector2) bool

Checks whether this vector is greater than or equal to other.

func (*Vector2) IsInf

func (v *Vector2) IsInf(sign int) bool

IsInf reports whether any vector coordinate is an infinity, according to sign. If sign > 0, IsInf reports whether any coordinate is positive infinity. If sign < 0, IsInf reports whether any coordinate is negative infinity. If sign == 0, IsInf reports whether any coordinate is either infinity.

func (*Vector2) IsNaN

func (v *Vector2) IsNaN() bool

Reports whether any vector coordinates is an IEEE 754 “not-a-number” value.

func (*Vector2) IsNull

func (v *Vector2) IsNull() bool

Returns true if X and Y equals to 0

func (*Vector2) Len

func (v *Vector2) Len() float64

Returns the length of this vector

func (*Vector2) Len2

func (v *Vector2) Len2() float64

Returns the squared length of this vector

func (*Vector2) Lerp

func (v *Vector2) Lerp(other *Vector2, t float64) *Vector2

Linearly interpolates between two points.

func (*Vector2) Lesser

func (v *Vector2) Lesser(other *Vector2) bool

Checks whether this vector is lesser than other.

func (*Vector2) LesserEq

func (v *Vector2) LesserEq(other *Vector2) bool

Checks whether this vector is lesser than or equal to other.

func (*Vector2) Mul

func (v *Vector2) Mul(other *Vector2) *Vector2

func (*Vector2) MulScalar

func (v *Vector2) MulScalar(scalar float64) *Vector2

func (*Vector2) MulScalars

func (v *Vector2) MulScalars(x, y float64) *Vector2

func (*Vector2) Normalize

func (v *Vector2) Normalize() *Vector2

Returns vector with a magnitude of 1 of this vector.

func (*Vector2) Perp

func (v *Vector2) Perp() *Vector2

Returns a new vector perpendicular from this one.

func (*Vector2) Reflect

func (v *Vector2) Reflect(other *Vector2) *Vector2

Returns a reflected vector off the plane defined by a normal.

func (*Vector2) Reverse

func (v *Vector2) Reverse() *Vector2

Returns a new vector that is reversed from this one.

func (*Vector2) Rotate

func (v *Vector2) Rotate(angle float64) *Vector2

Returns a new vector rotated counter-clockwise by the specified number of radians.

func (*Vector2) Scale

func (v *Vector2) Scale(x float64) *Vector2

Returns a new vector scaled in the direction of X and Y by value x

func (*Vector2) Set

func (v *Vector2) Set(x, y float64) *Vector2

func (*Vector2) SignedAngle

func (v *Vector2) SignedAngle(other *Vector2) float64

Returns signed angle (theta) between two vectors.

func (*Vector2) SmoothDamp

func (v *Vector2) SmoothDamp(target, currentVelocity *Vector2, smoothTime, deltaTime float64) *Vector2

Gradually changes a vector towards a desired goal over time. The vector is smoothed by some spring-damper like function, which will never overshoot. The most common use is for smoothing a follow camera. Original code by Unity.

func (*Vector2) SmoothDampMaxSpeed

func (v *Vector2) SmoothDampMaxSpeed(target, currentVelocity *Vector2, smoothTime, deltaTime, maxSpeed float64) *Vector2

Gradually changes a vector towards a desired goal over time. The vector is smoothed by some spring-damper like function, which will never overshoot. The most common use is for smoothing a follow camera. Original code by Unity.

func (*Vector2) String

func (v *Vector2) String() string

func (*Vector2) Sub

func (v *Vector2) Sub(other *Vector2) *Vector2

func (*Vector2) SubScalar

func (v *Vector2) SubScalar(scalar float64) *Vector2

func (*Vector2) SubScalars

func (v *Vector2) SubScalars(x, y float64) *Vector2

Jump to

Keyboard shortcuts

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