Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertices method should accept generators #229

Closed
hx2A opened this issue Feb 2, 2023 · 6 comments
Closed

Vertices method should accept generators #229

hx2A opened this issue Feb 2, 2023 · 6 comments

Comments

@hx2A
Copy link
Collaborator

hx2A commented Feb 2, 2023

  ![image](https://user-images.githubusercontent.com/3694604/216197226-d37cb3c2-3cc7-4c5a-9018-ec2d0aee911b.png)
import trimesh
import shapely
# https://iamkate.com/data/12-bit-rainbow/
palette = (
    '#817', '#a35', '#c66', '#e94',
    '#ed0', '#9d5', '#4d8', '#2cb',
    '#0bc', '#09c', '#36b', '#639'
    )

def setup():
    global m
    size(400, 400, P3D)
    no_stroke()
    polygon = shapely.geometry.Polygon([(-100, -100), (0, -100),
                                        (0, 0), (-50, -50), (-100, 0)])
    m = trimesh.creation.extrude_polygon(polygon, 30)
      
def draw():
    background(0)
    translate(width /2, height / 2)
    rotate_x(QUARTER_PI)
    rotate_y(radians(mouse_x))
    for i, face in enumerate(m.faces):
        fill(palette[i % 12])
        with begin_closed_shape():
            vertices([m.vertices[v] for v in face])

@hx2A, would it be too hard to make vertices() accept a generator so we could avoid building that list?

Originally posted by @villares in #228

@villares
Copy link
Collaborator

villares commented Feb 4, 2023

Do you think it would be a good idea to add that to lines() and points() too?

@hx2A
Copy link
Collaborator Author

hx2A commented Feb 4, 2023

Yes, absolutely. Also the 3 curve methods (bezier_vertices(), etc).

@hx2A hx2A added the good first issue Good for newcomers label Mar 5, 2023
@shyam-sunder-19
Copy link

So this requires a loop to iterate over the generator passed in as argument? I believe this needs to be done for vertices(), lines(), points() and the 3 curves. Lmk if I can proceed with this.

@hx2A
Copy link
Collaborator Author

hx2A commented Mar 8, 2023

So this requires a loop to iterate over the generator passed in as argument? I believe this needs to be done for vertices(), lines(), points() and the 3 curves. Lmk if I can proceed with this.

No, no loops. You'll need to detect if the passed argument is a generator. If it is, convert it to a list, and then proceed with the existing code.

@hx2A hx2A removed the good first issue Good for newcomers label Mar 10, 2023
@hx2A
Copy link
Collaborator Author

hx2A commented Mar 10, 2023

I looked into this some more and I realized fixing this requires some extra complications that would be hard to explain. I removed the good first issue tag because it is not that. But for those who are interested, one can detect if a param is a generator with isinstance(obj, types.GeneratorType).

hx2A added a commit that referenced this issue Mar 10, 2023
support generators for lines(), points(), etc

fix for #229
@hx2A
Copy link
Collaborator Author

hx2A commented Mar 10, 2023

Fixed with #253

@hx2A hx2A closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants