pub struct Vector<T, const N: usize>(/* private fields */);Expand description
A generic, fixed-size vector with compile-time dimension checking.
The Vector type represents a mathematical vector with N components
of type T. It provides common vector operations and integrates with
the vector-space trait ecosystem.
§Type Parameters
T: The scalar type of vector components (must implement relevant traits for operations)N: The dimension of the vector (must be a compile-time constant)
§Examples
Basic usage with f32:
use simple_vectors::Vector;
let v = Vector::new([1.0, 2.0, 3.0]);
assert_eq!(v[0], 1.0);
assert_eq!(v[1], 2.0);
assert_eq!(v[2], 3.0);Using with integer types:
use simple_vectors::Vector;
let int_vec = Vector::new([1, 2, 3, 4]);
let scaled = int_vec * 2;
assert_eq!(scaled, Vector::new([2, 4, 6, 8]));Implementations§
Source§impl<T, const N: usize> Vector<T, N>
impl<T, const N: usize> Vector<T, N>
Sourcepub const fn new(elements: [T; N]) -> Self
pub const fn new(elements: [T; N]) -> Self
Creates a new vector from the given array of elements.
This is a const function, allowing vector creation in const contexts.
§Arguments
elements- An array ofNelements to initialize the vector
§Examples
use simple_vectors::Vector;
const V: Vector<i32, 3> = Vector::new([1, 2, 3]);
assert_eq!(V, Vector::new([1, 2, 3]));Creating a 2D vector:
use simple_vectors::Vector;
let point = Vector::new([10.5, 20.3]);Trait Implementations§
Source§impl<T, const N: usize> AddAssign for Vector<T, N>
impl<T, const N: usize> AddAssign for Vector<T, N>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl<T: Real, const N: usize, const I: usize> Basis<I> for Vector<T, N>
impl<T: Real, const N: usize, const I: usize> Basis<I> for Vector<T, N>
Source§fn unit_basis() -> Self
fn unit_basis() -> Self
Creates an unit basis of the vector space.
Source§fn basis_of(magnitude: T) -> Self
fn basis_of(magnitude: T) -> Self
Creates a scaled basis of the vector space of the specified magnitude.
Source§fn basis_mut(&mut self) -> &mut Self::Scalar
fn basis_mut(&mut self) -> &mut Self::Scalar
Queries a basis of a vector space as a mutable reference.
Source§fn with_basis(self, magnitude: Self::Scalar) -> Self
fn with_basis(self, magnitude: Self::Scalar) -> Self
Creates a new vector with a single basis set to a different value.
Source§impl<T, const N: usize> DivAssign<T> for Vector<T, N>
impl<T, const N: usize> DivAssign<T> for Vector<T, N>
Source§fn div_assign(&mut self, other: T)
fn div_assign(&mut self, other: T)
Performs the
/= operation. Read moreSource§impl<T: Real, const N: usize> InnerSpace for Vector<T, N>
impl<T: Real, const N: usize> InnerSpace for Vector<T, N>
Source§fn magnitude2(self) -> Self::Scalar
fn magnitude2(self) -> Self::Scalar
The squared magnitude. Read more
Source§fn with_magnitude(self, magnitude: Self::Scalar) -> Self
fn with_magnitude(self, magnitude: Self::Scalar) -> Self
Sets the magnitude of a vector.
Source§fn with_direction(self, dir: Self) -> Self
fn with_direction(self, dir: Self) -> Self
Sets the direction of a vector.
Source§fn query_axis(self, dir: Self) -> Self::Scalar
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
fn normalized_project(self, dir: Self) -> Self
Projects a vector onto an already normalized direction vector.
Source§fn normalized_reject(self, dir: Self) -> Self
fn normalized_reject(self, dir: Self) -> Self
Rejects a vector from an already normalized direction vector.
Source§fn normalized_reflect(self, dir: Self) -> Self
fn normalized_reflect(self, dir: Self) -> Self
Reflects a vector from an already normalized direction vector.
Source§impl<T, const N: usize> MulAssign<T> for Vector<T, N>
impl<T, const N: usize> MulAssign<T> for Vector<T, N>
Source§fn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
Performs the
*= operation. Read moreSource§impl<T, const N: usize> SubAssign for Vector<T, N>
impl<T, const N: usize> SubAssign for Vector<T, N>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-= operation. Read moreimpl<T: Copy, const N: usize> Copy for Vector<T, N>
impl<T: Eq, const N: usize> Eq for Vector<T, N>
impl<T, const N: usize> StructuralPartialEq for Vector<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for Vector<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for Vector<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for Vector<T, N>where
T: Send,
impl<T, const N: usize> Sync for Vector<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for Vector<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for Vector<T, N>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> Bases for Twhere
T: VectorSpace,
impl<T> Bases for Twhere
T: VectorSpace,
Source§fn unit_bases<const I: usize>() -> Selfwhere
Self: Basis<I>,
fn unit_bases<const I: usize>() -> Selfwhere
Self: Basis<I>,
Creates the specified unit basis of the vector space.
Source§fn bases_of<const I: usize>(magnitude: Self::Scalar) -> Selfwhere
Self: Basis<I>,
fn bases_of<const I: usize>(magnitude: Self::Scalar) -> Selfwhere
Self: Basis<I>,
Creates the specified basis of the vector of the specified magnitude.
Source§fn bases<const I: usize>(&self) -> Self::Scalarwhere
Self: Basis<I>,
fn bases<const I: usize>(&self) -> Self::Scalarwhere
Self: Basis<I>,
Queries the specified basis of a vector space.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more