diagrams declarative vector graphics in haskell
play

Diagrams: Declarative Vector Graphics in Haskell Brent Yorgey NY - PowerPoint PPT Presentation

Diagrams: Declarative Vector Graphics in Haskell Brent Yorgey NY Haskell Users Group November 25, 2013 Part I: Demo! Part II: Lessons for EDSL design Take home Domain analysis is hard! Take home Domain analysis is hard! Be in it for


  1. Diagrams: Declarative Vector Graphics in Haskell Brent Yorgey NY Haskell Users’ Group November 25, 2013

  2. Part I: Demo!

  3. Part II: Lessons for EDSL design

  4. Take home Domain analysis is hard!

  5. Take home Domain analysis is hard! Be in it for the long haul.

  6. History

  7. April 2008. Wanted: declarative, programmatic drawing.

  8. PGF/TikZ

  9. “How hard could it be?”

  10. After two weeks of feverish hacking, diagrams was born!

  11. After two weeks of feverish hacking, diagrams was born! It sucked.

  12. Paths

  13. What is a path ?

  14. type Path = [ Point ]

  15. Problem 1 ?

  16. Problem 2 type Path = [( P2 , CurveSpec )] ?

  17. Affine spaces

  18. Find the bug type Point = ( Double , Double ) type Vector = ( Double , Double ) instance (Num a , Num b ) ⇒ Num ( a , b ) where . . . parallelogram :: Point → Point → Point → Point parallelogram p 1 p 2 p 3 = p 1 − p 3 − p 2

  19. Affine spaces for programmers Confusing points and vectors is a type error!

  20. Affine spaces

  21. translate ( p 1 − p 2 ) ≡ translate p 1 − translate p 2

  22. translate ( p 1 − p 2 ) ≡ translate p 1 − translate p 2 Translations apply to points but not to vectors!

  23. (ˆ + ˆ) :: Vector → Vector → Vector ( . + ˆ) :: Point → Vector → Point ( . − . ) :: Point → Point → Vector

  24. . . . Paths Again

  25. type Path = [ Vector ]

  26. type Path = [ Segment ]

  27. type Path = ([ Segment ] , Bool) ?

  28. ( , True )?

  29. ( , True )?

  30. Our solution data Offset c v where OffsetOpen :: Offset Open v OffsetClosed :: v → Offset Closed v data Segment c v = Linear ( Offset c v ) | Cubic v v ( Offset c v )

  31. data Trail ′ l v where Line :: [ Segment Closed v ] → Trail ′ Line v Loop :: [ Segment Closed v ] → Segment Open v → Trail ′ Loop v glueLine :: Trail ′ Line v → Trail ′ Loop v closeLine :: Trail ′ Line v → Trail ′ Loop v :: Trail ′ Loop v → Trail ′ Line v cutLine

  32. Problem 3

  33. Problem 3 type Trail = [ Segment ] . . . type Path = [( Point , Trail )]

  34. Our solution data Located a = Loc { loc :: Point ( V a ) , unLoc :: a } newtype Path v = Path [ Located ( Trail v )]

Recommend


More recommend