pub struct Vector<T> {
pub data: Vec<T>,
}
Expand description
A vector of elements of type T
Fields§
§data: Vec<T>
Implementations§
Source§impl<T: Copy> Vector<T>
impl<T: Copy> Vector<T>
Sourcepub fn dot(&self, other: &Self) -> T
pub fn dot(&self, other: &Self) -> T
Computes the dot product with another vector.
§Example
use rusticle::Vector;
let v1 = Vector::new(vec![1.0, 2.0]);
let v2 = Vector::new(vec![3.0, 4.0]);
let result = v1.dot(&v2);
assert_eq!(result, 11.0);
Sourcepub fn norm(&self) -> f64
pub fn norm(&self) -> f64
Computes the norm (magnitude) of the vector.
§Example
use rusticle::Vector;
let v = Vector::new(vec![3.0, 4.0]);
let result = v.norm();
assert_eq!(result, 5.0);
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Returns a normalized version of the vector.
§Example
use rusticle::Vector;
let v = Vector::new(vec![3.0, 4.0]);
let result = v.normalize();
assert!((result.norm() - 1.0).abs() < 1e-10);
Sourcepub fn scale(&self, scalar: T) -> Selfwhere
T: Mul<Output = T>,
pub fn scale(&self, scalar: T) -> Selfwhere
T: Mul<Output = T>,
Returns a new vector scaled by a scalar.
§Example
use rusticle::Vector;
let v = Vector::new(vec![1.0, 2.0]);
let result = v.scale(2.0);
assert_eq!(result, Vector::new(vec![2.0, 4.0]));
Trait Implementations§
impl<T> StructuralPartialEq for Vector<T>
Auto Trait Implementations§
impl<T> Freeze for Vector<T>
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> UnwindSafe for Vector<T>where
T: UnwindSafe,
Blanket Implementations§
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