Skip to main content

Vector2

Struct Vector2 

Source
pub struct Vector2 {
    pub x: f64,
    pub y: f64,
}
Expand description

A free vector in the plane.

Fields§

§x: f64

X component.

§y: f64

Y component.

Implementations§

Source§

impl Vector2

Source

pub const ZERO: Self

The zero vector.

Source

pub const X: Self

Unit vector along +X.

Source

pub const Y: Self

Unit vector along +Y.

Source

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

A vector from components.

Source

pub const fn to_array(self) -> [f64; 2]

Components as an array.

Source

pub const fn from_array([x, y]: [f64; 2]) -> Self

A vector from an array.

Source

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

Dot product.

Two terms, so no fused multiply-add; see Vector::cross for why.

Source

pub fn cross(self, other: Self) -> f64

The scalar cross product: the signed area of the parallelogram the two vectors span. Positive when other is counter-clockwise from self.

Source

pub fn square_magnitude(self) -> f64

Squared magnitude.

Source

pub fn magnitude(self) -> f64

Magnitude.

Source

pub const fn perpendicular(self) -> Self

This vector rotated a quarter turn counter-clockwise. Exact: no trigonometry involved.

Source

pub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>

This vector scaled to unit length.

§Errors

OgeomError::Construction if the magnitude is below tol.confusion(), or if any component is non-finite.

Source

pub fn is_finite(self) -> bool

Whether both components are finite.

Source

pub fn is_zero(self, tol: Tolerances) -> bool

Whether the magnitude is within tol.confusion() of zero.

Source

pub fn is_equal(self, other: Self, tol: Tolerances) -> bool

Whether two vectors agree component-wise within tol.confusion().

Source

pub fn angle(self, other: Self, tol: Tolerances) -> OgeomResult<f64>

Angle to other, in (-π, π], positive counter-clockwise.

§Errors

OgeomError::Construction if either vector is degenerate.

Source

pub fn lerp(self, other: Self, t: f64) -> Self

Linear interpolation, t = 0 giving self.

Source

pub const fn to_3d(self) -> Vector

This vector with a Z component of zero.

Trait Implementations§

Source§

impl Add for Vector2

Source§

type Output = Vector2

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vector2> for Point2

Source§

type Output = Point2

The resulting type after applying the + operator.
Source§

fn add(self, v: Vector2) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Vector2

Source§

fn add_assign(&mut self, o: Self)

Performs the += operation. Read more
Source§

impl AddAssign<Vector2> for Point2

Source§

fn add_assign(&mut self, v: Vector2)

Performs the += operation. Read more
Source§

impl Blend for Vector2

Source§

fn zero() -> Self

The additive identity.
Source§

fn scale(self, k: f64) -> Self

Scale by a factor.
Source§

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

Add another value.
Source§

fn lerp(self, other: Self, t: f64) -> Self

self * (1 - t) + other * t.
Source§

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

Subtract, via scaling by -1.
Source§

impl Clone for Vector2

Source§

fn clone(&self) -> Vector2

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Vector2

Source§

impl Debug for Vector2

Source§

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

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

impl Default for Vector2

Source§

fn default() -> Vector2

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

impl Div<f64> for Vector2

Source§

type Output = Vector2

The resulting type after applying the / operator.
Source§

fn div(self, s: f64) -> Self

Performs the / operation. Read more
Source§

impl DivAssign<f64> for Vector2

Source§

fn div_assign(&mut self, s: f64)

Performs the /= operation. Read more
Source§

impl From<Direction2> for Vector2

Source§

fn from(d: Direction2) -> Self

Converts to this type from the input type.
Source§

impl Mul<Vector2> for Matrix2

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vector2) -> Vector2

Performs the * operation. Read more
Source§

impl Mul<Vector2> for f64

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vector2) -> Vector2

Performs the * operation. Read more
Source§

impl Mul<f64> for Vector2

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, s: f64) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Vector2

Source§

fn mul_assign(&mut self, s: f64)

Performs the *= operation. Read more
Source§

impl Neg for Vector2

Source§

type Output = Vector2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector2

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for Vector2

Source§

impl Sub for Vector2

Source§

type Output = Vector2

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vector2> for Point2

Source§

type Output = Point2

The resulting type after applying the - operator.
Source§

fn sub(self, v: Vector2) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Vector2

Source§

fn sub_assign(&mut self, o: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<Vector2> for Point2

Source§

fn sub_assign(&mut self, v: Vector2)

Performs the -= operation. Read more

Auto Trait Implementations§

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

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

§

impl<T, Right> ClosedDiv<Right> for T
where T: Div<Right, Output = T> + DivAssign<Right>,

§

impl<T, Right> ClosedDivAssign<Right> for T
where T: ClosedDiv<Right> + DivAssign<Right>,

§

impl<T, Right> ClosedMul<Right> for T
where T: Mul<Right, Output = T> + MulAssign<Right>,

§

impl<T, Right> ClosedMulAssign<Right> for T
where T: ClosedMul<Right> + MulAssign<Right>,

§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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.