How to accept any float?

I have something like the below (as a working but not-generic stopgap measure)..

How would you suggest making it generic so that I can use any size of float? Or, should I make it like really generic and use ::Zero too?

pub fn write_scale_matrix(width:f64, height:f64, depth:f64, out:&mut [f32]) {
  out[0] = width as f32;
  out[1] = 0.0;
  out[2] = 0.0;
  out[3] = 0.0;
  out[4] = 0.0;
  out[5] = height as f32;
  out[6] = 0.0;
  out[7] = 0.0;
  out[8] = 0.0;
  out[9] = 0.0;
  out[10] = depth as f32;
  out[11] = 0.0;
  out[12] = 0.0;
  out[13] = 0.0;
  out[14] = 0.0;
  out[15] = 1.0;
}

Use the num crate like so: Rust Playground

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.