Instrumenting extensions with GPL and copyright notes.
[shapes.git] / resources / extensions / shiftoff.shext
blob746eaf88b101d70db1785b32b64ec3ca05fd81e2
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 Henrik Tidefelt
17  **/
19 ##needs centering
21 to_lft: 0
22 to_llft: 1
23 to_bot: 2
24 to_lrt: 3
25 to_rt: 4
26 to_urt: 5
27 to_top: 6
28 to_ulft: 7
29 to_center: 8
31 dirtopoint: \ d .>
32  [if d == to_center (0,0)
33   [if d == to_lft (1,0)
34    [if d == to_rt (~1,0)
35     [if d == to_bot (0,1)
36      [if d == to_top (0,~1)
37       [if d == to_llft (1,1)
38        [if d == to_lrt (~1,1)
39         [if d == to_urt (~1,~1)
40          [if d == to_ulft (1,~1)
41           [error [sprintf [`The following direction constant was not recognized by dirtopoint: %g´ d]]]]]]]]]]]]
43 to_dir: \ z .>
44   [if z.x > 0
45     [if z.y > 0
46       [if [abs z.x] > 2*[abs z.y]
47         to_rt
48        [if [abs z.y] > 2*[abs z.x]
49         to_top
50         to_urt]]
51       [if [abs z.x] > 2*[abs z.y]
52         to_rt
53        [if [abs z.y] > 2*[abs z.x]
54         to_bot
55         to_lrt]]]
56     [if z.y > 0
57       [if [abs z.x] > 2*[abs z.y]
58         to_lft
59        [if [abs z.y] > 2*[abs z.x]
60         to_top
61         to_ulft]]
62       [if [abs z.x] > 2*[abs z.y]
63         to_lft
64        [if [abs z.y] > 2*[abs z.x]
65         to_bot
66         to_llft]]]]
68 dir_to: \ d .> [dir 180° + d * 45°]
70 shiftoff: \ obj d .> [centerat obj [dirtopoint d]]
71 shiftoffwlm: \ obj d .> [centeratwlm obj [dirtopoint d]]