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:
f32 is NaN, or
f32 is infinity or negative infinity, or
f32 is greater or less than the maximum/minimum of the target type
I implemented TryFrom to give a descriptive error in such cases.
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.
As conversions between vector types were not possible yet, I made some macros and made those possible.
As
f32
toi32
/u32
may be problematic due to either one of those:f32
isNaN
, orf32
is infinity or negative infinity, orf32
is greater or less than the maximum/minimum of the target type I implementedTryFrom
to give a descriptive error in such cases.Implementing
TryFrom
is not possible for types out of the crate, so I used a module-privateTryFromExt
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.