Skip to content
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

Add parametric generalizations for segments, trails, Located, etc. #92

Merged
merged 29 commits into from
Jul 18, 2013

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Jul 14, 2013

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 Paths because that wouldn't really make sense---Paths can have multiple components; their semantics is not a parametric function).

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

{-# 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.

mgsloan and others added 29 commits August 4, 2012 11:59
Conflicts:
	src/Diagrams/TwoD/Combinators.hs
Conflicts:
	src/Diagrams/Segment.hs
	src/Diagrams/TwoD/Combinators.hs
In particular, some non-trivial merging had to be done to incorporate
the major Trail refactoring (@705a9b28).

Conflicts:
	src/Diagrams/Path.hs
	src/Diagrams/Segment.hs
	src/Diagrams/TwoD/Path.hs
	src/Diagrams/TwoD/Segment.hs
…and Trail'

Redesign mostly has to do with arc length and accuracy of approximations.
Also, get rid of the 'TransInv' from the definition of Located.  It
was sort of questionable in the first place (e.g. what does it mean to
apply TransInv to something which is already translation invariant?)
and was making it very difficult to define the parametric instances.
@mgsloan mgsloan merged commit 9ecc5fb into master Jul 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typeclasses for parametric paths
2 participants