Operations
StaticVector and DynamicVector support the same core set of operations: element-wise
addition and subtraction, scalar scaling, the dot product, and the Euclidean norm. The
example below constructs two StaticVectors and runs each of them in turn.
#![allow(unused)]
fn main() {
use rustebra::vector::StaticVector;
pub(crate) fn run() {
println!("== StaticVector ==");
let a = StaticVector::new([1.0, 2.0, 3.0]);
let b = StaticVector::new([4.0, 5.0, 6.0]);
println!("a = {a:?}");
println!("b = {b:?}");
println!("a + b = {:?}", a.add(&b));
println!("a - b = {:?}", a.sub(&b));
println!("a scaled by 2 = {:?}", a.scale(2.0));
println!("a . b = {}", a.dot(&b));
println!("||a|| = {:.4}", a.norm());
}
}
Gotchas
add,sub, anddotonStaticVectorreturn a plain value, not aResult— the const genericNguarantees both operands have the same length at compile time, so there’s nothing to fail at runtime. TheDynamicVectorequivalents returnResult<_, LengthMismatch>instead, since twoDynamicVectors aren’t guaranteed to match in length.scaletakes the factor by value (T, not&T), matchingScalar’sCopybound — pass the number directly rather than a reference.