Nalgebra Vector3/Point3 initialisation

I am using statics as I am using #[wasm_bindgen] and want to have some persistent data between calls from JS. I am not sure why I can initialize a Vector3 but not a Point3 using nalgebra ... is there a way I can have a static Point3 and if so how do I initialize it?

extern crate nalgebra;

use nalgebra::Point3;
use nalgebra::Vector3;

// This works
static mut TV:Vector3<u16> = Vector3::new(0, 0, 0);

// This doesn't
static mut TP:Point3<u16> = Point3::new(0, 0, 0);

fn main() {
    println!("Hello from rust.");
    unsafe {
        println!("{:?}", TV);
        println!("{:?}", TP);



   Compiling playground v0.0.1 (/playground)
error[E0015]: cannot call non-const fn `geometry::point_construction::<impl OPoint<u16, Const<3_usize>>>::new` in statics
 --> src/
7 | static mut TP:Point3<u16> = Point3::new(0, 0, 0);
  |                             ^^^^^^^^^^^^^^^^^^^^
  = note: calls in statics are limited to constant functions, tuple structs and tuple variants

For more information about this error, try `rustc --explain E0015`.
error: could not compile `playground` due to previous error

Well, Point3::new isn't a const fn (while Vector3::new is). Looking at the source there, it seems it trivially could be -- you could send a PR.

In the meanwhile you can:

static mut TP:Point3<u16> = Point3 { coords: Vector3::new(0, 0, 0) };

Thanks @quinedot - that works - possibly there is some reason why Point3::new isn't a const - I will investigate.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.