rustgd / cgmath

A linear algebra and mathematics library for computer graphics.
https://docs.rs/cgmath
Apache License 2.0
1.13k stars 155 forks source link

Declare vector constructors to be const #475

Closed nstoddard closed 5 years ago

nstoddard commented 5 years ago

This makes it easier to create vectors in constants.

kvark commented 5 years ago

Could you please expand this to other types, so that our const usage is more consistent?

nstoddard commented 5 years ago

Done. Unfortunately the only other types that const can be added to at the moment are points, because for the other types the compiler gives an error:

error: trait bounds other than `Sized` on const fn parameters are unstable                               
  --> src/matrix.rs:84:6                                                                                 
   |                                                                                                     
84 | impl<S: BaseFloat> Matrix2<S> {                                                                     
   |      ^                                                                                              
nstoddard commented 5 years ago

Actually, it looks like this might be doable for other types by removing the trait bounds from the constructors. I'll look into that tomorrow.

nstoddard commented 5 years ago

I updated this PR to declare the rest of the constructors to be const.

Since this change requires removing trait bounds, it has the side effect that it's now technically possible to create, for instance, an Euler<T> for any type, not just angles. This probably isn't a problem because such a type can't accidentally be used as if it actually contained angles (also, types like Vector2 could already be used to hold any type in a similar manner).

kvark commented 5 years ago

Thank you! bors r+

bors[bot] commented 5 years ago

Build succeeded