Advertisement
GeneralGDA

Swizzling

Feb 7th, 2015
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.42 KB | None | 0 0
  1. private float[DIMENSION] coords = [0.0f, 0.0f, 0.0f, 1.0f];
  2.  
  3. @property pure auto opDispatch(const string swizzling)() const
  4. if (swizzling.length == DIMENSION || swizzling.length == DIMENSION - 1)
  5. {
  6.     immutable expression = "coords".repeat().take(swizzling.length)
  7.         .zip(swizzling).map!( a => format("%s[%c]", a[0], a[1].toUpper()) ).reduce!((a,b) => a ~ "," ~ b);
  8.  
  9.     mixin( "return Vector4 (" ~ expression ~ ");" );
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement