Vector

Struct Vector 

Source
pub struct Vector { /* private fields */ }
Expand description

A 2D vector

Implementations§

Source§

impl Vector

Source

pub fn new(x: f64, y: f64) -> Vector

Create a new vector

Source

pub fn x(&self) -> f64

Get the x value

Source

pub fn y(&self) -> f64

Get the y value

Source

pub fn dot(&self, other: &Vector) -> f64

Perform the inner product with another vector

Source

pub fn negate(&mut self)

Negate the vector, negating each of the components

Source

pub fn magnitude(&self) -> f64

Get the length (magnitude) of the vector

Source

pub fn normalise(&mut self)

Normalise the vector

Trait Implementations§

Source§

impl<'a, 'b> Add<&'b Position> for &'a Vector

Source§

type Output = Position

The resulting type after applying the + operator.
Source§

fn add(self, other: &'b Position) -> Position

Performs the + operation. Read more
Source§

impl<'a, 'b> Add<&'b Vector> for &'a Position

Source§

type Output = Position

The resulting type after applying the + operator.
Source§

fn add(self, other: &'b Vector) -> Position

Performs the + operation. Read more
Source§

impl<'a, 'b> Add<&'b Vector> for &'a Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

fn add(self, other: &'b Vector) -> Vector

Performs the + operation. Read more
Source§

impl Add for Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<'a> AddAssign<&'a Vector> for Vector

Source§

fn add_assign(&mut self, other: &Self)

Performs the += operation. Read more
Source§

impl AddAssign for Vector

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. 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 Mul<Vector> for f64

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vector) -> Vector

Performs the * operation. Read more
Source§

impl Mul<f64> for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> Vector

Performs the * operation. Read more
Source§

impl PartialEq for Vector

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Vector

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.