March gen: refactor for easier testing

This commit is contained in:
Théophile Bastian 2018-02-09 01:52:00 +01:00
parent 0f60c717f0
commit f15151ff57

View file

@ -171,7 +171,7 @@ def all_transforms():
return output return output
def do_main(base_cases): def gen_index(base_cases):
transforms = all_transforms() transforms = all_transforms()
index = [None for x in range(256)] index = [None for x in range(256)]
for case in base_cases: for case in base_cases:
@ -197,21 +197,32 @@ def do_main(base_cases):
if has_unbound: if has_unbound:
raise RuntimeError("Some cases were not generated.") raise RuntimeError("Some cases were not generated.")
print(PREAMBLE) return index
print(("static const TriVect edges_of_intersection[256] = {"))
def pretty_print(index):
output = ""
output += PREAMBLE
output += "static const TriVect edges_of_intersection[256] = {\n"
for (case_id, case) in enumerate(index): for (case_id, case) in enumerate(index):
print("\tTriVect({") output += "\tTriVect({\n"
for (tri_id, tri) in enumerate(case.triangles): for (tri_id, tri) in enumerate(case.triangles):
print('\t\t' + dump_tri(tri), output += '\t\t{}{}'.format(
end=",\n" if tri_id != len(case.triangles) - 1 else '\n') dump_tri(tri),
print('\t\t})', end=',\n' if case_id != len(index) - 1 else '\n') ",\n" if tri_id != len(case.triangles) - 1 else '\n')
print("};") output += '\t\t})' + (',\n' if case_id != len(index) - 1 else '\n')
output += "};\n"
return output
def main(): def do_main(base_cases):
base_cases = [ print(pretty_print(gen_index(base_cases)))
BASE_CASES = [
# Source: <https://en.wikipedia.org/wiki/File:MarchingCubes.svg> # Source: <https://en.wikipedia.org/wiki/File:MarchingCubes.svg>
# -- 1 -- # -- 1 --
TriangulatedCube(set(), []), TriangulatedCube(set(), []),
@ -555,7 +566,10 @@ def main():
], ],
]), ]),
] ]
do_main(base_cases)
def main():
do_main(BASE_CASES)
if __name__ == "__main__": if __name__ == "__main__":