Skip to main content

Vec2Ext

Trait Vec2Ext 

Source
pub trait Vec2Ext {
    // Required methods
    fn distance_to(self, other: Vec2) -> f32;
    fn distance_squared_to(self, other: Vec2) -> f32;
    fn angle_to(self, other: Vec2) -> f32;
    fn rotated(self, angle: f32) -> Vec2;
    fn move_toward(self, target: Vec2, max_delta: f32) -> Vec2;
    fn reflect(self, normal: Vec2) -> Vec2;
    fn projected_onto(self, onto: Vec2) -> Vec2;
    fn perp(self) -> Vec2;
    fn to_ivec(self) -> IVec2;
}
Expand description

Extension trait for Vec2 with game-oriented helpers.

Required Methods§

Source

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

Euclidean distance to another point.

Source

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

Squared Euclidean distance (avoids sqrt).

Source

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

Angle from self to other in radians.

Source

fn rotated(self, angle: f32) -> Vec2

Rotate this vector by angle radians.

Source

fn move_toward(self, target: Vec2, max_delta: f32) -> Vec2

Move toward target by at most max_delta.

Source

fn reflect(self, normal: Vec2) -> Vec2

Reflect this vector off a surface with the given normal.

Source

fn projected_onto(self, onto: Vec2) -> Vec2

Project self onto onto.

Source

fn perp(self) -> Vec2

Perpendicular vector (rotated 90° clockwise in Y-down).

Source

fn to_ivec(self) -> IVec2

Convert to integer pixel coordinates.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§