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

Graphics.Collage: Not possible to make shapes with holes. #269

Closed
justinmanley opened this Issue Jun 10, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@justinmanley

justinmanley commented Jun 10, 2015

The standard wisdom on making shapes with holes in them using HTML canvas seems to be to draw the outer shape in one direction, then to draw the inner shape in the other direction. Once both shapes have been drawn, then they are filled as a unit. This results in a hole in the form of the inner shape.

The current Graphics.Collage library doesn't allow for shapes to be drawn separately, then filled together.

Perhaps the addition of a function groupShapes : List Shape -> Shape would be sufficient?

@justinmanley

This comment has been minimized.

Show comment
Hide comment
@justinmanley

justinmanley Jun 11, 2015

Thinking further...

The HTML canvas API isn't necessarily the best API for drawing shapes. What if Elm programmers could express these ways of combining shapes in a declarative fashion that was easy to read and understand, rather than being buried in the clockwise/counterclockwise direction in which the coordinates describing a shape happen to be listed?

For example, Graphics.Canvas might expose the following additional functions:

intersect, union, symmetricDifference : Shape -> Shape -> Shape

Symmetric difference would allow for the expedient creation of shapes containing holes.

This would be much more difficult to implement than the groupShapes function I described in my first comment. I'm not sure how these high-level functions could map on to the nonzero winding rule that is built in to canvas elements.

I haven't come across any precedents for these kinds of functions. Popular JavaScript graphics libraries for canvas - e.g. fabric.js and paper.js don't put shapes together in this way; neither does Haskell's Diagrams library.

That said, I think that the functions described above would provide an elegant set of primitives worthy of Elm.

justinmanley commented Jun 11, 2015

Thinking further...

The HTML canvas API isn't necessarily the best API for drawing shapes. What if Elm programmers could express these ways of combining shapes in a declarative fashion that was easy to read and understand, rather than being buried in the clockwise/counterclockwise direction in which the coordinates describing a shape happen to be listed?

For example, Graphics.Canvas might expose the following additional functions:

intersect, union, symmetricDifference : Shape -> Shape -> Shape

Symmetric difference would allow for the expedient creation of shapes containing holes.

This would be much more difficult to implement than the groupShapes function I described in my first comment. I'm not sure how these high-level functions could map on to the nonzero winding rule that is built in to canvas elements.

I haven't come across any precedents for these kinds of functions. Popular JavaScript graphics libraries for canvas - e.g. fabric.js and paper.js don't put shapes together in this way; neither does Haskell's Diagrams library.

That said, I think that the functions described above would provide an elegant set of primitives worthy of Elm.

@justinmanley

This comment has been minimized.

Show comment
Hide comment
@justinmanley

justinmanley Jun 11, 2015

There are unambiguous ways to intersect, union, and take the symmetric difference of closed shapes which are not self-intersecting using the nonzero winding rule.

There is, however, some ambiguity regarding closed self-intersecting shapes (which might be created using Graphics.Collage.polygon). In particular, it's not immediately clear how to determine the orientation (clockwise/counterclockwise) for a shape which is self-intersecting.

justinmanley commented Jun 11, 2015

There are unambiguous ways to intersect, union, and take the symmetric difference of closed shapes which are not self-intersecting using the nonzero winding rule.

There is, however, some ambiguity regarding closed self-intersecting shapes (which might be created using Graphics.Collage.polygon). In particular, it's not immediately clear how to determine the orientation (clockwise/counterclockwise) for a shape which is self-intersecting.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 11, 2016

Member

Sorry this did not get attention til now! The Graphics.* modules now live in evancz/elm-graphics so I am trying to get stuff migrated over there.

That said, I would like to keep that API stable for now. I expect to be focusing on <canvas> for professional users and "friendly graphics" for learning as separate use cases. Progress will be made when those start happening.

Member

evancz commented May 11, 2016

Sorry this did not get attention til now! The Graphics.* modules now live in evancz/elm-graphics so I am trying to get stuff migrated over there.

That said, I would like to keep that API stable for now. I expect to be focusing on <canvas> for professional users and "friendly graphics" for learning as separate use cases. Progress will be made when those start happening.

@evancz evancz closed this May 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment