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

source

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);
source

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);
source

pub fn normal(self) -> Self

Returns the vector’s normal vector, i.e. a vector that is perpendicular to this vector

source

pub fn magnitude(self) -> f64

Returns the magnitude of the vector, i.e. its length if viewed as a line

source

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

source

pub fn project_onto(self, other: Self) -> Self

Returns the projection of this vector onto another vector

source

pub fn rotate(self, rotation: Radians) -> Self

Rotate a vector by the given amount (counterclockwise)

source

pub fn rotate_clockwise(self, rotation: Radians) -> Self

Rotate a vector by the given amount (clockwise)

source

pub fn negative(self) -> Self

Negates the vector, returning a vector with the same magnitude pointing in the opposite direction.

Trait Implementations§

source§

impl Add for Vector

§

type Output = Vector

The resulting type after applying the + operator.
source§

fn add(self, other: Self::Output) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for Vector

source§

fn clone(&self) -> Vector

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Vector

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Vector

source§

fn default() -> Vector

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Vector

source§

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 Div<f64> for Vector

§

type Output = Vector

The resulting type after applying the / operator.
source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
source§

impl From<Point> for Vector

source§

fn from(point: Point) -> Self

Converts to this type from the input type.
source§

impl From<Vector> for Point

source§

fn from(vector: Vector) -> Self

Converts to this type from the input type.
source§

impl Mul<f64> for Vector

§

type Output = Vector

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
source§

impl PartialEq for Vector

source§

fn eq(&self, other: &Vector) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Vector

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub for Vector

§

type Output = Vector

The resulting type after applying the - operator.
source§

fn sub(self, other: Self::Output) -> Self::Output

Performs the - operation. Read more
source§

impl Copy for Vector

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,