I'm working on a library which will provide a trait for axis-aligned bounding boxes (AABB) operations. The trait is declared like this:
trait Aabb {
type Precision : Zero + One + Num + PartialOrd + Copy;
// [...]
}
I don't care which precision the user chooses, as long as these constraints are respected (though I don't really expect integer types to be chosen).
I'm having trouble using literals. Some operations require constant values, as an example:
let extension = 0.1;
aabb.extend(extension);
This doesn't work because Aabb::extend
expects Aabb::Precision
and not a float. My solution was something like this:
let mut ten = Aabb::Precision::zero();
for _ in 0..10 {
ten = ten + Aabb::Precision::one();
}
aabb_extension = Aabb::Precision::one() / ten;
This works, but I need to resort to this every time I need a specific number and it is getting cumbersome. Is this really the only way?