neglect / neglect / scripts /

import os
import time
from itertools import product

vec_sets = {
    2:  ["xy", "rg", "st"],
    3:  ["xyz", "rgb", "stp"],
    4:  ["xyzw", "rgba", "stpq"]

def swizzle_permutations(set):
    for x in xrange(2, 5):
        for p in product(set, repeat=x):
            yield x, ''.join(p)

os.chdir((os.path.dirname(__file__) or '.') + '/../cpplib/include/neglect')

for vector_size, sets in vec_sets.iteritems():
    with open('' % vector_size, 'w') as f:
        f.write('// this file was automatically generated by\n'
                '// %s on %s.  DO NOT EDIT\n\n' %
                (os.path.basename(__file__), time.ctime()))
        for set in sets:
            for result_size, name in swizzle_permutations(set):
                if name == set:
                    f.write('const vector<T, %d> &%s() const { return *this; }\n' % (
                    f.write('vector<T, %d> %s() const { return vector<T, %d>(%s); }\n' % (
                        ', '.join(name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.