Skip to main content

Vector

Struct Vector 

Source
pub struct Vector<const N: usize, T = Scalar> { /* private fields */ }

Implementations§

Source§

impl<T: Number, const N: usize> Vector<N, T>

Source

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

Source

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

Source

pub fn neg(&self) -> Self

Source

pub fn prod_scalar(&self, s: T) -> Self

Source

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

Source

pub fn norm_sq(&self) -> T

Source

pub fn norm(&self) -> T

Source

pub fn try_norm(&self) -> GeopResult<T>

|self|, failing where [Scalar::sqrt] refuses the squared length instead of panicking like Self::norm.

Source

pub fn normalize(&self) -> GeopResult<Self>

Source

pub fn orthonormal_complement(&self) -> GeopResult<Vec<Self>>

N - 1 orthonormal vectors perpendicular to self, or an error for a zero self. They are the columns other than the first of the Householder reflection H = I - 2 w wᵀ / (wᵀ w), w = v̂ + σ e_0, which swaps v̂ = self / |self| and σ e_0: H is orthogonal, so its columns are orthonormal, and all but the first are perpendicular to v̂. The sign σ of v̂_0 keeps wᵀ w = 2 (1 + |v̂_0|) >= 2 away from cancellation, so the result is well conditioned for every v̂.

Source

pub fn distance_to_segment(&self, a: &Self, b: &Self) -> T

How far self is from the segment a..b.

Source

pub fn could_be_equal(&self, other: &Self) -> bool

True if every component could_be_equal other’s.

Source

pub fn union(&self, other: &Self) -> Self

The componentwise [Scalar::union] of self and other.

Source§

impl<const N: usize> Vector<N>

Source

pub fn sharpen(&self) -> Self

Componentwise [Scalar::sharpen] — see that method’s own doc comment for when collapsing a value to a single representative point is a safe, free choice (you only ever needed some point within the interval) versus a silent loss of real uncertainty.

Source§

impl<T: Number> Vector<3, T>

Source

pub fn across(&self) -> GeopResult<[Self; 2]>

Two unit directions square to the unit vector self and to each other: the first from whichever of x, y, z runs least along it — the first no other definitely runs less along, so that an axis a hair off one of them does not pick between two by noise. A free choice, made the same way wherever a direction across an axis is measured from: a joint’s turns, a frame’s x, a sketch’s parallel.

Source

pub fn prod_cross(&self, other: &Self) -> Self

Source

pub fn could_be_parallel(&self, other: &Self) -> bool

Whether self and other could be parallel, in either sense: their cross product could be zero.

Source

pub fn rotated_about(&self, axis: &Self, cos: T, sin: T) -> Self

self turned about the unit vector axis by the angle with cosine cos and sine sin (Rodrigues’ formula).

Source

pub fn homogeneous(&self, w: T) -> Vector4<T>

The point self with weight w, homogeneous: (w x, w y, w z, w). Taken as it is where the weight is exactly one: multiplying by it would only widen it by rounding.

Source

pub fn dehomogenized(&self) -> GeopResult<Vector2<T>>

The point the homogeneous 2-D point (w x, w y, w) stands for, (x, y): each coordinate divided by the weight (not multiplied by its inverse, which rounds twice).

Source§

impl<T: Number> Vector<4, T>

Source

pub fn dehomogenized(&self) -> GeopResult<Vector3<T>>

The point the homogeneous 3-D point (w x, w y, w z, w) stands for, (x, y, z): each coordinate divided by the weight (not multiplied by its inverse, which rounds twice).

Source§

impl<T: Number> Vector<2, T>

Source

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

The 2-D cross product self.x * other.y - self.y * other.x: the z component of the 3-D one, positive when other lies counter-clockwise of self.

Source

pub fn homogeneous(&self, w: T) -> Vector3<T>

The point self with weight w, homogeneous: (w x, w y, w) — taken as it is where the weight is exactly one (see Vector3::homogeneous).

Source

pub fn perp(&self) -> Self

Rotated 90 degrees counter-clockwise — by neg, which is exact, where subtracting from zero would round.

Source

pub fn rotate(&self, c: T, s: T) -> Self

Rotated counter-clockwise by the angle with cosine c and sine s.

Source§

impl<T: Default + Copy, const N: usize> Vector<N, T>

Source

pub fn new() -> Self

Source

pub fn size(&self) -> usize

Source§

impl<T: Number, const N: usize> Vector<N, T>

Source

pub fn from_array(data: [T; N]) -> Self

Source

pub fn to_array(&self) -> [T; N]

Its components, as an array.

Source

pub fn to_f64_array(&self) -> [f64; N]

Its components as plain numbers (Scalar::to_f64, the midpoint): for output and drawing, never for construction.

Source

pub fn map<U: Number>(&self, f: impl Fn(T) -> U) -> Vector<N, U>

Every component mapped by f — into dual numbers, say.

Source

pub fn get(&self, idx: &[usize]) -> T

Element access using a multi-index slice; only the first index is used (vectors are 1-D). Panics if idx is empty.

Source§

impl<T: Number> Vector<2, T>

Source

pub fn swap_xy(&self) -> Self

Source§

impl<T: Number, const N: usize> Vector<N, T>

Source

pub fn zero() -> Self

Source

pub fn axis(k: usize) -> Self

The k-th coordinate axis: one at k, zero elsewhere.

Source

pub fn head<const M: usize>(&self) -> Vector<M, T>

The first M components — e.g. the Cartesian part H of a homogeneous point (H, w), which is not its position H / w.

Source§

impl<const N: usize> Vector<N>

Source

pub fn everything() -> Self

Every component set to Scalar::ENTIRE — could_be_equals any other vector of the same dimension componentwise.

Source

pub fn interpolate(a: &Self, b: &Self, alpha: Scalar) -> Self

Componentwise Scalar::interpolate: a at alpha=0, b at alpha=1. See that method’s doc comment for why this beats a manual a*(1-alpha) + b*alpha when components of a/b may coincide.

Trait Implementations§

Source§

impl<const N: usize, T: Clone> Clone for Vector<N, T>

Source§

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

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<const N: usize, T: Copy> Copy for Vector<N, T>

Source§

impl<const N: usize, T: Debug> Debug for Vector<N, T>

Source§

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

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

impl<T: Default + Copy, const N: usize> Default for Vector<N, T>

Source§

fn default() -> Self

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

impl<'de, T: Number, const N: usize> Deserialize<'de> for Vector<N, T>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Number, const N: usize> Display for Vector<N, T>

Source§

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

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

impl<const N: usize> Exact for Vector<N>

Its components, each exactly.

Source§

fn write<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Source§

fn read<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Source§

impl<T, const N: usize> Index<usize> for Vector<N, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Default + Copy, const N: usize> IndexMut<usize> for Vector<N, T>

Source§

fn index_mut(&mut self, idx: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<const N: usize> Iterate for Vector<N>

Source§

fn same(&self, other: &Self) -> bool

Whether self and other are the same value — the same enclosure, not merely overlapping ones.
Source§

impl<const N: usize> Mergeable for Vector<N>

Source§

fn could_be_equal(&self, other: &Self) -> bool

Source§

fn union(&self, other: &Self) -> Self

Source§

impl<const N: usize, T: PartialEq> PartialEq for Vector<N, T>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: Number, const N: usize> Serialize for Vector<N, T>

A vector serializes as the array of its components’ midpoints — how it travels to a viewer, which draws points, not enclosures — and reads back from an array of plain numbers, each a sharp scalar.

Source§

fn serialize<Ser: Serializer>( &self, serializer: Ser, ) -> Result<Ser::Ok, Ser::Error>

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

impl<const N: usize, T: PartialEq> StructuralPartialEq for Vector<N, T>

Auto Trait Implementations§

§

impl<const N: usize, T> Freeze for Vector<N, T>
where T: Freeze,

§

impl<const N: usize, T> RefUnwindSafe for Vector<N, T>
where T: RefUnwindSafe,

§

impl<const N: usize, T> Send for Vector<N, T>
where T: Send,

§

impl<const N: usize, T> Sync for Vector<N, T>
where T: Sync,

§

impl<const N: usize, T> Unpin for Vector<N, T>
where T: Unpin,

§

impl<const N: usize, T> UnsafeUnpin for Vector<N, T>
where T: UnsafeUnpin,

§

impl<const N: usize, T> UnwindSafe for Vector<N, T>
where T: UnwindSafe,

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

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

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