Debian Codegraph @

src/Diagrams/TwoD/Deform.hs

raw symbols SCIP
1 module Diagrams.TwoD.Deform where
2
3 import Control.Lens
4
5 import Diagrams.Deform
6
7 import Linear.V2
8 import Linear.Vector
9
10 -- | The parallel projection onto the plane x=0
11 parallelX0 :: (R1 v, Num n) => Deformation v v n
12 parallelX0 = Deformation (_x .~ 0)
13
14 -- | The perspective division onto the plane x=1 along lines going
15 -- through the origin.
16 perspectiveX1 :: (R1 v, Functor v, Fractional n) => Deformation v v n
17 perspectiveX1 = Deformation $ \p -> p ^/ (p ^. _x)
18
19 -- | The parallel projection onto the plane y=0
20 parallelY0 :: (R2 v, Num n) => Deformation v v n
21 parallelY0 = Deformation (_y .~ 0)
22
23 -- | The perspective division onto the plane y=1 along lines going
24 -- through the origin.
25 perspectiveY1 :: (R2 v, Functor v, Floating n) => Deformation v v n
26 perspectiveY1 = Deformation $ \p -> p ^/ (p ^. _y)
27
28 -- | The viewing transform for a viewer facing along the positive X
29 -- axis. X coördinates stay fixed, while Y coördinates are compressed
30 -- with increasing distance. @asDeformation (translation unitX) <>
31 -- parallelX0 <> frustrumX = perspectiveX1@
32 facingX :: (R1 v, Functor v, Fractional n) => Deformation v v n
33 facingX = Deformation $
34 \p -> let x = p ^. _x
35 in p ^/ x & _x .~ x
36
37 facingY :: (R2 v, Functor v, Fractional n) => Deformation v v n
38 facingY = Deformation $
39 \p -> let y = p ^. _y
40 in p ^/ y & _y .~ y
41