pub struct Vector {
pub x: f64,
pub y: f64,
}Expand description
A vector
Fields§
§x: f64The x component of the Vector
y: f64The 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§
impl Copy for Vector
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
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 UnsafeUnpin 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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