diagrams/diagrams-lib — pull request #92 by byorgey (2013-07-14 21:07:31+00:00)
Title: Add parametric generalizations for segments, trails, Located, etc.

This is the continuation of the work started by @mgsloan in #53. (@mgsloan, if you have a chance, can you take a look at what I've done and see if it makes sense?) We had some functions for computing parametrizations and arc length of segments, splitting segments, and adjusting their length in various ways. This generalizes all these things via type classes and adds instances for trails and `Located` things (though not `Path`s because that wouldn't really make sense---`Path`s can have multiple components; their semantics is not a parametric function).

Here's a demonstration that exercises quite a bit of the code:

``` haskell

{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Backend.Cairo.CmdLine
import Diagrams.Coordinates
import Diagrams.Prelude

dia :: Double -> Diagram Cairo R2
dia pct = trailLike t1 # lc green
<> trailLike t2 # lc blue # lw 0.1
where
t1, t2 :: Located (Trail R2)
(t1,t2) = s `splitAtParam` p (al * pct)

al :: Double
al = stdArcLength s

s :: Located (Trail R2)
s = cubicSpline False [1 & 3, 4 & 6, 2 & 9, 1 & 1, 3 & 4]

p :: Double -> Double
p = stdArcLengthToParam s

a :: Active (Diagram Cairo R2)
a = (dia <$> ui) # centerXY # stretch 3

main :: IO ()
main = animMain (a <> pure (square 10 # fc white))
```

The output can be found here: http://www.cis.upenn.edu/~byorgey/hosted/TrailParam.mp4

Closes #53.