Skip to content

Instantly share code, notes, and snippets.

@rubber-duck
Created May 22, 2013 06:18
Show Gist options
  • Select an option

  • Save rubber-duck/5625608 to your computer and use it in GitHub Desktop.

Select an option

Save rubber-duck/5625608 to your computer and use it in GitHub Desktop.
static int coordIndex(char c)() pure nothrow
{
switch(c)
{
case 'x': return 0;
case 'y': return 1;
case 'z': return N > 2 ? 2 : -1;
case 'w': return N > 3 ? 3 : -1;
default:
return -1;
}
}
static bool coordValid(char c)() pure nothrow { return coordIndex!c != -1; }
@property VectorTN!(T, coords.length) opDispatch(string coords)() pure const nothrow
if(coords.length > 1 && coords.length <= 4 && coordsValidGetter!coords)
{
VectorTN!(T, coords.length) result;
result[0] = members[coordIndex!(coords[0])];
result[1] = members[coordIndex!(coords[1])];
static if(coords.length > 2)
result[2] = members[coordIndex!(coords[2])];
static if(coords.length > 3)
result[3] = members[coordIndex!(coords[3])];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment