fu5ha / ultraviolet

A wide linear algebra crate for games and graphics.
https://crates.io/crates/ultraviolet
750 stars 81 forks source link

impl TryFrom between vector types (#104) #126

Closed joeftiger closed 3 years ago

joeftiger commented 3 years ago

As conversions between vector types were not possible yet, I made some macros and made those possible.

As f32 to i32/u32 may be problematic due to either one of those:

Implementing TryFrom is not possible for types out of the crate, so I used a module-private TryFromExt to circumvent it.

In case of converting from float vectors to int vectors (like Vec2 -> IVec2), any float precision will be lost, resulting in a lossy conversion that is practically "flooring" the float value to the next integer.

I wrote some simple tests for Vec2 conversions, these could be extended but they showcase the correctness of the above mentioned possible float issues.

I am open for feedback and possible changes to this pull request.

fu5ha commented 3 years ago

Released a new version with these and previous changes just fyi :)

joeftiger commented 3 years ago

Released a new version with these and previous changes just fyi :)

nice! I can delete the git path in my Cargo.toml now :D