Struct myelin_geometry::Vector
source · pub struct Vector {
pub x: f64,
pub y: f64,
}
Expand description
A vector
Fields§
§x: f64
The x component of the Vector
y: f64
The y component of the Vector
Implementations§
source§impl Vector
impl Vector
sourcepub fn dot_product(self, other: Self) -> f64
pub fn dot_product(self, other: Self) -> f64
Calculates the dot product of itself and another vector
§Examples
use myelin_geometry::Vector;
// a · b = c
let a = Vector { x: 2.0, y: 3.0 };
let b = Vector { x: -4.0, y: 10.0 };
let c = a.dot_product(b);
assert_eq!(22.0, c);
sourcepub fn cross_product(self, other: Self) -> f64
pub fn cross_product(self, other: Self) -> f64
Calculates the cross product of itself and another vector
§Examples
use myelin_geometry::Vector;
// a × b = c
let a = Vector { x: 2.0, y: 3.0 };
let b = Vector { x: -4.0, y: 10.0 };
let c = a.cross_product(b);
assert_eq!(32.0, c);
sourcepub fn normal(self) -> Self
pub fn normal(self) -> Self
Returns the vector’s normal vector, i.e. a vector that is perpendicular to this vector
sourcepub fn magnitude(self) -> f64
pub fn magnitude(self) -> f64
Returns the magnitude of the vector, i.e. its length if viewed as a line
sourcepub fn unit(self) -> Self
pub fn unit(self) -> Self
Returns the unit vector of this vector, i.e. a vector with the same direction and a magnitude of 1
sourcepub fn project_onto(self, other: Self) -> Self
pub fn project_onto(self, other: Self) -> Self
Returns the projection of this vector onto another vector
sourcepub fn rotate(self, rotation: Radians) -> Self
pub fn rotate(self, rotation: Radians) -> Self
Rotate a vector by the given amount (counterclockwise)
sourcepub fn rotate_clockwise(self, rotation: Radians) -> Self
pub fn rotate_clockwise(self, rotation: Radians) -> Self
Rotate a vector by the given amount (clockwise)
Trait Implementations§
source§impl<'de> Deserialize<'de> for Vector
impl<'de> Deserialize<'de> for Vector
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq for Vector
impl PartialEq 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> 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