2

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.

1 Answer 1

7

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]]))
answered Oct 18, 2014 at 18:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.