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