macro_rules! dim {
(x) => { ... };
(y) => { ... };
(z) => { ... };
(w) => { ... };
}Expand description
Converts an identifier x, y, z or w to a usize value for indexing
Using any identifier apart from the above or multiple identifiers will result in a compile time error
It is recommended to use parentheses when calling this macro for clarity
let x_index: usize = dim!(x);
assert_eq!(x_index, 0usize);
let y_index = dim!(y);
assert_eq!(y_index, 1usize);
// ERROR: Only allowed to use one of x, y, z or w
// let fifth_dimension = dim!(v);
// ERROR: Only accepts one identifier
// If multiple dimensions are what you need, see the dims macro
// let sixth_and_seventh = dim!(u, t);This can be especially useful for indexing a PointND (or any collection indexable with a usize)
If a dimension is passed that is out of bounds, it will result in a compile time error
let p = PointND::new([0,1,2]);
let y_val = p[dim!(y)];
assert_eq!(y_val, 1);
// ERROR: Index out of bounds
// let w_val = p[dim!(w)];