March generator: fix pretty printing
Fix various display/valid C++ generation problems.
This commit is contained in:
parent
65cb03487d
commit
b5ae4b5463
1 changed files with 19 additions and 10 deletions
|
@ -10,6 +10,15 @@ from functools import reduce
|
|||
import sys
|
||||
|
||||
|
||||
PREAMBLE = """
|
||||
#include "MarchingCubes.hpp"
|
||||
|
||||
typedef MarchingCubes::CubeTri Tri;
|
||||
typedef std::vector<Tri> TriVect;
|
||||
typedef MarchingCubes::CubeEdge Edge;
|
||||
"""
|
||||
|
||||
|
||||
class Vert:
|
||||
frnt_bot_l = (0, 0, 1)
|
||||
frnt_bot_r = (1, 0, 1)
|
||||
|
@ -40,9 +49,9 @@ class Edge:
|
|||
|
||||
def dump(self):
|
||||
def cbool(val):
|
||||
return "true" if val else "false"
|
||||
return "1" if val else "0"
|
||||
|
||||
return "MarchingCubes::CubeEdge({}, {}, {}, {}, {}, {})".format(
|
||||
return "Edge({}, {}, {}, {}, {}, {})".format(
|
||||
cbool(self.vert[0][0]),
|
||||
cbool(self.vert[0][1]),
|
||||
cbool(self.vert[0][2]),
|
||||
|
@ -108,8 +117,8 @@ class TriangulatedCube:
|
|||
|
||||
|
||||
def dump_tri(tri):
|
||||
return ("MarchingCubes::CubeTri({{{}, {}, {}}})".format(
|
||||
tri[0].dump(), tri[1].dump(), tri[2].dump))
|
||||
return ("Tri({}, {}, {})".format(
|
||||
tri[0].dump(), tri[1].dump(), tri[2].dump()))
|
||||
|
||||
|
||||
def rot_general(vert, fixed, ax1, ax2):
|
||||
|
@ -212,16 +221,16 @@ def do_main(base_cases):
|
|||
if has_unbound:
|
||||
raise RuntimeError("Some cases were not generated.")
|
||||
|
||||
print(("static const std::vector<MarchingCubes::CubeTri> "
|
||||
"edges_of_intersection[256] = {"))
|
||||
print(PREAMBLE)
|
||||
print(("static const TriVect edges_of_intersection[256] = {"))
|
||||
|
||||
for (case_id, case) in enumerate(index):
|
||||
print("\tstd::vector<MarchingCubes::CubeTri>({")
|
||||
print("\tTriVect({")
|
||||
|
||||
for (tri_id, tri) in enumerate(case.triangles):
|
||||
print(dump_tri(tri),
|
||||
end=",\n" if tri_id == len(case.triangles) - 1 else '\n')
|
||||
print('})', end=',\n' if case_id == len(base_cases) - 1 else '\n')
|
||||
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("};")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue