evancz/Elm — pull request #220 by mgold (2013-08-17 15:53:25+00:00)
Title: Add rotateAround and movePolar transformations.

This pull request consists of three new functions on Forms, the first two required by the third:

`movePolar`, an incredibly handy one-liner.

`boundingBox`, which find the BoundingBox (new record type) of a Form. Note that it does not account for the affine transformations done to the form; that is, it is the bounding box in the form's own coordinate system. Scale and move would be easy to add, but rotation is difficult for shapes and paths, as you would need to walk the list of vertices to find the centerpoint and then again to rotate them. However, all we really need is the width and height for...

`rotateAround`, which takes a Position argument in addition to an angle and moves the Form so that it appears to have been rotated around the (for example) bottom right of the Form's BoundingBox. Due to the implementation of boundingBox, if some Forms in a group are transformed to lie outside of the bounding box, then this fails to work properly. However, it is tolerant of affine transformations on the top-level form.

boundingBox and rotateAround are much longer and more involved than the other functions in this file, but that's because they extract information that is present only implicitly in the existing data structures. They also require many branches of case analysis. The geometry, while not particularly complex, is not trivial either.

You can play with these changes in [this sprout](http://share-elm.com/sprout/520f97c1e4b098db14c54784).