rustrust-cratesnalgebra

Elegant way to turn a Vector3 into Vector4


This may be a silly question, but is there a way to move between different types inside the nalgebra crate without having to recur to using the new() method each time, I found that going from a Vector4 to a vector3 can be done with the .xyz method. but after scrolling in the documentation i didn't found what I was looking for.

I was expecting something like Is there something that works like this

let holder = Vector3::new(1,1,1);
let new_holder = Vector4::from((holder, 2));


Solution

  • There is push():

    use nalgebra::Vector3;
    
    fn main() {
        let src = Vector3::new(1, 2, 3);
        let dst = src.push(4);
        println!("{dst:?}");
    }