timjs / elm-collage

Create interactive vector graphics and position them relative to each other
BSD 3-Clause "New" or "Revised" License
58 stars 19 forks source link

Tighter envelops instead of rectangular bounding boxes #14

Open timjs opened 7 years ago

timjs commented 7 years ago

This, off course, would be awesome! Strange things like the top-right of a circle being out of the shape won't happen any more. Two things are important to keep in mind however:

  1. It is quite hard to get this right for all possible shapes.
  2. It will make the library more complicated, as we'll want to calculate envelopes in arbitrary directions using 2D vectors, as Haskell Diagrams does.

Summarised: awesome to extend envelopes further, but I currently don't have the time and knowledge to implement this myself.

(First brought up in #4.)

Kwarrtz commented 7 years ago

For what shapes in particular do you think this would be problematic? Calculating the extents of polygons and ellipses can be done efficiently using basic highschool geometry, and obviously anything rectangular such as images and text would be pretty trivial. Handling paths might be a bit more complicated, but the problem there seems fundamentally to be one of design, not implementation. (Determining the extent of arbitrary HTML elements could also be difficult, but that would be true even with purely rectangular envelopes I should think.)

timjs commented 7 years ago

Maybe you’re right and it is only a problem of design instead of implementation. My main concern is keeping the library simple. When calculating arbitrary envelopes we’ll need vectors instead of the simple Up|Down|Right|Left enumeration. Obviously we can provide functions to cover those basic directions.

On 18 Oct 2017, 05:34 +0200, Dathan Ault-McCoy , wrote:

For what shapes in particular do you think this would be problematic? Calculating the extents of polygons and ellipses can be done efficiently using basic highschool geometry. Obviously anything rectangular such as images and text would be pretty trivial. Handling paths might be a bit more complicated, but the problem there seems fundamentally to be one of design, not implementation. (Determining the extent of arbitrary HTML elements could also be difficult, but that would be true even with purely rectangular envelopes I should think.) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Kwarrtz commented 7 years ago

Is there a reason to use vectors instead of angles? For instance, you could define

envelope : Float -> Collage msg -> Float

to return the distance from the origin to the edge of the envelope at an angle specified by the float argument. Then you could define

up = pi/2
down = 3*pi/2
left = pi
right = 0

So you could still use envelope up just like before (except lower case), but you could also say envelope 0.833. What simplicity do you see being lost here?

timjs commented 7 years ago

Would be totally fine to use angles I think!