Replace some tabs by spaces in interaction messages
[shapes.git] / resources / extensions / pathmapping.shext
blob4f134cc6873778a617998e6300fdd4a345e59b75
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 Henrik Tidefelt
17  **/
19 ##push Shapes
21 pathmap:
23   meeter: \ p1 p2 →
24    [if p1.null? >> [debuglog_before p1 ...] >> [debuglog_before "{n} ...]
25        p2
26        (escape_continuation cont
27          @handler_NoIntersection: (\ pth1 pth2 →
28               (escape_continue cont (pth1.begin--pth1.end>(1%C^[angle (-pth1.end.rT)]))--((1%C^[angle (-pth2.begin.T)])<pth2.begin--pth2.end)))
29          |
30          {
31            t: [intersection p1 p2] >> [debuglog_before `search...´ ...] >> [debuglog_after `found´ ...]
32            [meetpaths [p1 0]--t [approximator p2 t.p]--[p2 ∞]]
33          }
34        )
35    ]
37   helper: \ f sl1 sl2 res →
38     [if sl2.looped
39         res
40   [helper f sl2 sl2+1 [meeter res [f sl1 sl2]]]]
42   \ pth f →
43   {
44     tmp: [helper f [pth 0] [pth 1] emptypath]
45     [if pth.closed?
46         tmp--cycle
47   tmp]
48   }
52 sidepath: \ pth dst →
53  @defaultunit:1%C
54  |
55  [pathmap pth
56    \ sl1 sl2 →
57      (sl1.p + sl1.N*dst)>(^[angle sl1.T])--
58      (^[angle sl2.rT])<(sl2.p - sl2.rN*dst)]
60 sidepath2: \ pth dst →
61   [pathmap pth
62     \ sl1 sl2 →
63     {
64       p0: sl1.p + sl1.N*dst
65       p3: sl2.p - sl2.rN*dst
66       p0 > ( (1/3)*sl1.v*( (sl1.T*p3) / (sl1.T*sl2.p) ) ^ [angle sl1.T] ) --
67       ( (1/3)*sl2.rv*( (sl2.rT*p0) / (sl2.rT*sl1.p) ) ^ [angle sl2.rT] ) < p3
68     }]
70 ##pop Shapes