I’m trying to port a very basic dual contouring algorithm written in Python (here) to C++. I’m not a Python programmer so some of the language syntax is a bit foreign to me.
Specifically, this block of code is giving me trouble:
# Estimate hermite data
h_data = [estimate_hermite(f, df, o+cube_verts[e[0]], o+cube_verts[e[1]])
for e in cube_edges if cube_signs[e[0]] != cube_signs[e[1]]]
The part that doesn’t make sense is that e
is defined in the third line for the for
loop, but is then used in the second line. In this case, is the declaration of the loop defined after the content of the loop? I’ve tried to find other cases of this in Python, but have failed so far.
That is a list comprehension. Spread out a bit, it would look something like:
h_data = []
for e in cube_edges:
if cube_signs[e[0]] != cube_signs[e[1]]:
h_data.append(estimate_hermite(f, df, o+cube_verts[e[0]], o+cube_verts[e[1]]))