pub struct Vector {
pub x: f64,
pub y: f64,
}Expand description
A standard 2D vector implementaion.
Fields§
§x: f64§y: f64Implementations§
Source§impl Vector
impl Vector
Sourcepub fn new(x: f64, y: f64) -> Self
pub fn new(x: f64, y: f64) -> Self
Create new vector. This is just a helper given the fields are public.
Sourcepub fn normalized(&self) -> Vector
pub fn normalized(&self) -> Vector
returns a copy of this vector with a length of 1
Sourcepub fn scale_e(&self, sx: f64, sy: f64) -> Vector
pub fn scale_e(&self, sx: f64, sy: f64) -> Vector
element wise scaling with seperate x and y scaling factors
Sourcepub fn rotate(&self, theta: f64) -> Vector
pub fn rotate(&self, theta: f64) -> Vector
apply a rotation matrix constructed around theta to this vector
Sourcepub fn reflect(&self, normal: &Vector) -> Vector
pub fn reflect(&self, normal: &Vector) -> Vector
Caluate a normal reflection of this vector as a direction vector
against a surface with a normal vector of normal.
§Parameters:
- self: a
Vectorrepresenting the direction to be relected. - normal: a
Vectorrepresenting the normal of the surface being reflected off.
Neither vector needs to be normalised.
Trait Implementations§
Source§impl PartialOrd for Vector
impl PartialOrd for Vector
impl Copy for Vector
impl StructuralPartialEq for Vector
Auto Trait Implementations§
impl Freeze for Vector
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnwindSafe for Vector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more