tarcieri / micromath

Embedded Rust arithmetic, 2D/3D vector, and statistics library
Apache License 2.0
402 stars 21 forks source link

Support for right hand side operations and division #105

Open exor2008 opened 10 months ago

exor2008 commented 10 months ago
let v = F32x3::from((1.0, 2.0, 3.0));

v * 2.0; // Supported
2.0 * v; // Not supported
1.0 / v; // Not supported
v / 10.0; // Not supported

May be also element-wise multiplication and division for vectors.

let v = F32x3::from((1.0, 2.0, 3.0));
let w = F32x3::from((3.0, 2.0, 1.0));

v.mult(w); // v*w -> cross product
v / w;

Can do PR if needed

sunsided commented 4 months ago

Sadly that doesn't work as of now due to Rust's coherence rules. It ends up in a classy

type parameter `C` must be covered by another type when it appears before the first local type (`Vector3d<C>`)

I'm assuming the problem might be solvable when trait specialization / default impl lands. Alternatively, one could specialize for the standard numeric types but in general, this simply cannot be implemented at the moment.