0 | module CyBy.Draw.Internal.Wedge
3 | import CyBy.Draw.Internal.CoreDims
4 | import CyBy.Draw.Internal.Label
15 | lineT : Point Id -> Point Id -> Maybe AffineTransformation
16 | lineT s e = (\phi => AT (rotation phi) (s - origin)) <$> angle (e - s)
19 | transform : (t : AffineTransformation) -> Point Id -> Point t
20 | transform t = convert
26 | parameters {auto cd : CoreDims}
32 | downCmds : (gap,bw,tot : Double) -> AffineTransformation -> Double -> List PathCmd
33 | downCmds gap bw tot t x =
34 | let dw := cd.wedgeWideEnd - cd.wedgeNarrowEnd
35 | l := cd.wedgeNarrowEnd + x * dw / tot
37 | P x1 y1 := transform t $
P px (l/2.0)
38 | P x2 y2 := transform t $
P px (l/(-2.0))
39 | in [M x1 y1, L x2 y2]
46 | wedgeDown : (start, end : Point Id) -> List PathCmd
48 | let Just t := lineT s e | Nothing => []
50 | bw := cd.downWedgeGap + cd.bondWidth
51 | True := len >= cd.bondWidth | False => []
52 | tot := floor $
(len - cd.bondWidth) / bw
53 | gap := (len - tot * bw) / 2.0
54 | in [0..cast tot] >>= downCmds gap bw (1.0 + tot) t . cast
58 | wedgeUp : (s,e : Point Id) -> List (SVGAttribute "polygon") -> SVGNode
60 | let Just t := lineT s e | Nothing => Empty
62 | P a b := transform t $
P 0 (cd.wedgeNarrowEnd / 2.0)
63 | P c d := transform t $
P 0 (cd.wedgeNarrowEnd / (-2.0))
64 | P e f := transform t $
P len (cd.wedgeWideEnd / (-2.0))
65 | P g h := transform t $
P len (cd.wedgeWideEnd / 2.0)
66 | in polygon (points [a,b,c,d,e,f,g,h] :: as)
76 | -> AffineTransformation
79 | waves sp gap pos t (a::tl) =
80 | let P xa ya := transform t $
P (gap + cast a * cd.halfWaveLength) 0
81 | cmd := A cd.waveAmplitude cd.waveAmplitude 0 False pos xa ya
82 | in waves (sp :< cmd) gap (not pos) t tl
83 | waves sp _ _ _ [] = sp <>> []
87 | wave : (start,end : Point Id) -> List PathCmd
89 | let Just t := lineT s e | Nothing => []
91 | True := len >= cd.halfWaveLength | False => []
92 | tot := floor (len / cd.halfWaveLength)
93 | gap := len - tot * cd.halfWaveLength
94 | P x y := transform t $
P gap 0
95 | in waves [<M x y] gap True t [1..cast tot]