Skip to main content

Vec2

2D vector type.

struct Vec2 {
// from native code
x: f32 = 0
y: f32 = 0
}

Fields

x

x: f32

y

y: f32

Methods

zero

fn zero(self) -> bool

Are all components of this vector equal to 0?

nonzero

fn nonzero(self) -> bool

Is at least one component of this vector not equal to 0?

square_magnitude

fn square_magnitude(self) -> f32

Calculates the magnitude of this vector, but squared. Useful when detecting relative distances, e.g. is object A or object B closer to object C?

magnitude

fn magnitude(self) -> f32

Calculates the magnitude of this vector, i.e. the square root of the sum of the components. square_magnitude can be often be used instead.

lerp

fn lerp(self, other: Vec2, t: f32) -> Vec2

Linearly interpolate between two vectors.

min

fn min(self, other: Vec2) -> Vec2

Find the min of each component from two vectors.

max

fn max(self, other: Vec2) -> Vec2

Find the max of each component from two vectors.

dot

fn dot(self, other: Vec2) -> f32

Calculate the dot product of two vectors.

normalise_or_zero

fn normalise_or_zero(self) -> Vec2

Normalise this vector, i.e. scale it such that it has a magnitude of 1. If the magnitude is already 0, return a 0 vector instead.