Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upGraphics.Collage: Not possible to make shapes with holes. #269
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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 -> ShapeSymmetric 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, intersect, union, symmetricDifference : Shape -> Shape -> ShapeSymmetric difference would allow for the expedient creation of shapes containing holes. This would be much more difficult to implement than the 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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
Sorry this did not get attention til now! The That said, I would like to keep that API stable for now. I expect to be focusing on |
justinmanley commentedJun 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 -> Shapewould be sufficient?