Skip to main content

Vector

Struct Vector 

Source
pub struct Vector<T> {
    pub x: T,
    pub y: T,
}
Expand description

The 2D vector type.

Fields§

§x: T

The component representing the x axis.

§y: T

The component representing the y axis.

Implementations§

Source§

impl<T> Vector<T>

Source

pub fn new(x: T, y: T) -> Self

Creates a new vector from its components.

Source§

impl<T: Zero> Vector<T>

Source

pub fn x(x: T) -> Self

Creates a new vector along the x axis.

Source

pub fn y(y: T) -> Self

Creates a new vector along the y axis.

Source§

impl<T> Vector<T>
where T: Mul<Output = T> + Sub<Output = T> + Copy,

Source

pub fn wedge(self, other: Self) -> Bivector<T>

Computes the wedge (exterior) product of two vectors, yielding a bivector.

Trait Implementations§

Source§

impl<T: Add<Output = T>> Add<Vector<T>> for Point<T>

Source§

type Output = Point<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector<T>) -> Self

Performs the + operation. Read more
Source§

impl<T> Add for Vector<T>
where T: Add<Output = T>,

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: AddAssign> AddAssign<Vector<T>> for Point<T>

Source§

fn add_assign(&mut self, other: Vector<T>)

Performs the += operation. Read more
Source§

impl<T> AddAssign for Vector<T>
where T: AddAssign,

Source§

fn add_assign(&mut self, __rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Real> Basis<0> for Vector<T>

Source§

fn unit_basis() -> Self

Creates an unit basis of the vector space.
Source§

fn basis_of(x: T) -> Self

Creates a scaled basis of the vector space of the specified magnitude.
Source§

fn basis(&self) -> Self::Scalar

Queries a basis of a vector space.
Source§

fn basis_mut(&mut self) -> &mut Self::Scalar

Queries a basis of a vector space as a mutable reference.
Source§

fn with_basis(self, x: T) -> Self

Creates a new vector with a single basis set to a different value.
Source§

impl<T: Real> Basis<1> for Vector<T>

Source§

fn unit_basis() -> Self

Creates an unit basis of the vector space.
Source§

fn basis_of(y: T) -> Self

Creates a scaled basis of the vector space of the specified magnitude.
Source§

fn basis(&self) -> Self::Scalar

Queries a basis of a vector space.
Source§

fn basis_mut(&mut self) -> &mut Self::Scalar

Queries a basis of a vector space as a mutable reference.
Source§

fn with_basis(self, y: T) -> Self

Creates a new vector with a single basis set to a different value.
Source§

impl<T: Clone> Clone for Vector<T>

Source§

fn clone(&self) -> Vector<T>

Returns a duplicate 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<T: Debug> Debug for Vector<T>

Source§

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

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

impl<T: Display> Display for Vector<T>

Source§

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

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

impl<T> Div<T> for Vector<T>
where T: Div<Output = T> + Copy,

Source§

type Output = Vector<T>

The resulting type after applying the / operator.
Source§

fn div(self, other: T) -> Self

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Vector<T>
where T: DivAssign + Copy,

Source§

fn div_assign(&mut self, other: T)

Performs the /= operation. Read more
Source§

impl<T: Real> DotProduct<Bivector<T>> for Vector<T>

Source§

type Output = Vector<T>

The output type of the dot product.
Source§

fn dot(&self, other: &Bivector<T>) -> Self

The dot product (contraction).
Source§

fn scalar(&self, other: &T) -> Self::Output

The scalar product (positive-definite). Read more
Source§

impl<T: Real> DotProduct<Rotor<T>> for Vector<T>

Source§

type Output = Vector<T>

The output type of the dot product.
Source§

fn dot(&self, other: &Rotor<T>) -> Self

The dot product (contraction).
Source§

fn scalar(&self, other: &T) -> Self::Output

The scalar product (positive-definite). Read more
Source§

impl<T: Real> DotProduct<Vector<T>> for Bivector<T>

Source§

type Output = Vector<T>

The output type of the dot product.
Source§

fn dot(&self, other: &Vector<T>) -> Vector<T>

The dot product (contraction).
Source§

fn scalar(&self, other: &T) -> Self::Output

The scalar product (positive-definite). Read more
Source§

impl<T: Real> DotProduct<Vector<T>> for Rotor<T>

Source§

type Output = Vector<T>

The output type of the dot product.
Source§

fn dot(&self, other: &Vector<T>) -> Vector<T>

The dot product (contraction).
Source§

fn scalar(&self, other: &T) -> Self::Output

The scalar product (positive-definite). Read more
Source§

impl<T: Real> DotProduct for Vector<T>

Source§

type Output = <Vector<T> as VectorSpace>::Scalar

The output type of the dot product.
Source§

fn dot(&self, other: &Self) -> T

The dot product (contraction).
Source§

fn scalar(&self, other: &T) -> Self::Output

The scalar product (positive-definite). Read more
Source§

impl<T> From<[T; 2]> for Vector<T>

Source§

fn from([x, y]: [T; 2]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<(T, T)> for Vector<T>

Source§

fn from((x, y): (T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vector<T>> for [T; 2]

Source§

fn from(_: Vector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vector<T>> for (T, T)

Source§

fn from(_: Vector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: FromStr> FromStr for Vector<T>

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(source: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<T> Mul<T> for Vector<T>
where T: Mul<Output = T> + Copy,

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Self

Performs the * operation. Read more
Source§

impl<T: Real> Mul for Vector<T>

Source§

type Output = Rotor<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Rotor<T>

Performs the * operation. Read more
Source§

impl<T> MulAssign<T> for Vector<T>
where T: MulAssign + Copy,

Source§

fn mul_assign(&mut self, other: T)

Performs the *= operation. Read more
Source§

impl<T: Neg<Output = T>> Neg for Vector<T>

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector<T>

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for Vector<T>

Source§

fn eq(&self, other: &Vector<T>) -> 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<T: Sub<Output = T>> Sub<Vector<T>> for Point<T>

Source§

type Output = Point<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector<T>) -> Self

Performs the - operation. Read more
Source§

impl<T> Sub for Vector<T>
where T: Sub<Output = T>,

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: SubAssign> SubAssign<Vector<T>> for Point<T>

Source§

fn sub_assign(&mut self, other: Vector<T>)

Performs the -= operation. Read more
Source§

impl<T> SubAssign for Vector<T>
where T: SubAssign,

Source§

fn sub_assign(&mut self, __rhs: Self)

Performs the -= operation. Read more
Source§

impl<T: Real> Transform<Vector<T>> for Rotor<T>

Source§

fn apply_point(&self, point: Vector<T>) -> Vector<T>

Applies this transformation to a point.
Source§

impl<T: Real> VectorSpace for Vector<T>

Source§

type Scalar = T

The scalar type of the vector space.
Source§

impl<T: Zero> Zero for Vector<T>

Source§

fn zero() -> Self

Source§

fn is_zero(&self) -> bool

Source§

impl<T: Copy> Copy for Vector<T>

Source§

impl<T: Eq> Eq for Vector<T>

Source§

impl<T> StructuralPartialEq for Vector<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector<T>
where T: Send,

§

impl<T> Sync for Vector<T>
where T: Sync,

§

impl<T> Unpin for Vector<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Vector<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Vector<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T, D> AffineSpace for T
where T: Sub<Output = D>, D: VectorSpace,

Source§

type Diff = D

The difference type.
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> Bases for T
where T: VectorSpace,

Source§

fn unit_bases<const I: usize>() -> Self
where Self: Basis<I>,

Creates the specified unit basis of the vector space.
Source§

fn bases_of<const I: usize>(magnitude: Self::Scalar) -> Self
where Self: Basis<I>,

Creates the specified basis of the vector of the specified magnitude.
Source§

fn bases<const I: usize>(&self) -> Self::Scalar
where Self: Basis<I>,

Queries the specified basis of a vector space.
Source§

fn bases_mut<const I: usize>(&mut self) -> &mut Self::Scalar
where Self: Basis<I>,

Queries the specified basis of a vector space as a mutable reference.
Source§

fn with_bases<const I: usize>(self, magnitude: Self::Scalar) -> Self
where Self: Basis<I>,

Creates a new vector with the specified basis set to a different value.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InnerSpace for T
where T: DotProduct<Output = <T as VectorSpace>::Scalar>,

Source§

fn magnitude2(&self) -> Self::Scalar

The squared magnitude. Read more
Source§

fn magnitude(&self) -> Self::Scalar

The magnitude of a vector.
Source§

fn normalize(self) -> Self

The normalized vector.
Source§

fn angle(&self, other: &Self) -> Self::Scalar

The angle between two vectors.
Source§

fn with_magnitude(self, magnitude: Self::Scalar) -> Self

Sets the magnitude of a vector.
Source§

fn with_direction(self, dir: Self) -> Self

Sets the direction of a vector.
Source§

fn query_axis(&self, dir: Self) -> Self::Scalar

The value of the vector along the specified axis.
Source§

fn normalized_project(self, dir: Self) -> Self

Projects a vector onto an already normalized direction vector.
Source§

fn project(self, dir: Self) -> Self

Projects a vector onto the specified direction vector.
Source§

fn normalized_reject(self, dir: Self) -> Self

Rejects a vector from an already normalized direction vector.
Source§

fn reject(self, dir: Self) -> Self

Rejects a vector from the specified direction vector.
Source§

fn normalized_reflect(self, dir: Self) -> Self

Reflects a vector from an already normalized direction vector.
Source§

fn reflect(self, dir: Self) -> Self

Reflects a vector from the specified direction vector.
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> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> VectorSpaceAssign for T