Updating documentation and examples with new core namespaces
[shapes.git] / resources / extensions / Shapes / Geometry / pathmapping.shext
blob00be84505c22521e1d8f179bdbf19cdac02bdd5c
1 /** This file is part of Shapes.
2  **
3  ** Shapes is free software: you can redistribute it and/or modify
4  ** it under the terms of the GNU General Public License as published by
5  ** the Free Software Foundation, either version 3 of the License, or
6  ** any later version.
7  **
8  ** Shapes is distributed in the hope that it will be useful,
9  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  ** GNU General Public License for more details.
12  **
13  ** You should have received a copy of the GNU General Public License
14  ** along with Shapes.  If not, see <http://www.gnu.org/licenses/>.
15  **
16  ** Copyright 2008, 2014, 2015 Henrik Tidefelt
17  **/
19 pathmap:
21   meeter: \ p1 p2 →
22    [if p1.null? >> [Debug..log_before p1 ...] >> [Debug..log_before "{n} ...]
23        p2
24        (escape_continuation cont
25          @handler_NoIntersection: (\ pth1 pth2 →
26               (escape_continue cont (pth1.begin--pth1.end>(1%C^[angle (-pth1.end.rT)]))--((1%C^[angle (-pth2.begin.T)])<pth2.begin--pth2.end)))
27          |
28          {
29            t: [intersection p1 p2] >> [Debug..log_before `search...´ ...] >> [Debug..log_after `found´ ...]
30            [meetpaths [p1 0]--t [approximator p2 t.p]--[p2 ∞]]
31          }
32        )
33    ]
35   helper: \ f sl1 sl2 res →
36     [if sl2.looped
37         res
38   [helper f sl2 sl2+1 [meeter res [f sl1 sl2]]]]
40   \ pth f →
41   {
42     tmp: [helper f [pth 0] [pth 1] Geometry..emptypath]
43     [if pth.closed?
44         tmp--cycle
45   tmp]
46   }
50 sidepath: \ pth dst →
51  Geometry..@defaultunit:1%C
52  |
53  [pathmap pth
54    \ sl1 sl2 →
55      (sl1.p + sl1.N*dst)>(^[angle sl1.T])--
56      (^[angle sl2.rT])<(sl2.p - sl2.rN*dst)]
58 sidepath2: \ pth dst →
59   [pathmap pth
60     \ sl1 sl2 →
61     {
62       p0: sl1.p + sl1.N*dst
63       p3: sl2.p - sl2.rN*dst
64       p0 > ( (1/3)*sl1.v*( (sl1.T*p3) / (sl1.T*sl2.p) ) ^ [angle sl1.T] ) --
65       ( (1/3)*sl2.rv*( (sl2.rT*p0) / (sl2.rT*sl1.p) ) ^ [angle sl2.rT] ) < p3
66     }]