Update standard extensions to new namespace hierarchy
[shapes.git] / resources / extensions / Shapes / Graphics / braces.shext
blob22b58a5b3d37f1e4cab83d7941d004eca4270f3b
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 genericBrace: \ p0 p1 height aEnd rEndFactor aMid rMidFactor extendLimitFactor →
21   rEnd: height * rEndFactor
22   rMid: height * rMidFactor
23   extendLimit: height * extendLimitFactor
24   r: p1 - p0
25   a0: [angle r]
26   n: [[rotate ~90°] height * [normalized r]]
27   [if [abs r] < extendLimit
28       p0>(rEnd^a0-aEnd)--(rMid^180°+a0-aMid)<(p0+0.5*r+n)>(rMid^a0+aMid)--(rEnd^180°+a0+aEnd)<p1
29       {
30         r: [normalized ../r] * extendLimit
31         tmp: p0>(rEnd^a0-aEnd)--(rMid^180°+a0-aMid)<(p0+0.5*r+n)>(rMid^a0+aMid)--(rEnd^180°+a0+aEnd)<(p0+r)
32   tmp1: tmp.begin--[tmp 1]
33   slmid: [tmp1 0.5*[abs tmp1]]
34   l1: [maximizer tmp1.begin--slmid [normalized n]].length
35   l2: slmid.length + [maximizer slmid--tmp1.end ~[normalized n]].length
36   sl1: tmp.begin + l1
37   sl2: tmp.begin + l2
38   sl3: tmp.end - l2
39   sl4: tmp.end - l1
40   stretchSeg: sl1--sl2
41   (tmp.begin--sl1>(stretchSeg.begin.v/3^))--[[shift 0.5*(../r - r)] (stretchSeg.end.v/3^)<sl2--sl3>(stretchSeg.end.v/3^)]--[[shift ../r - r] (stretchSeg.begin.v/3^)<sl4--tmp.end]
42       }]
45 heightBrace: [genericBrace aEnd:70° rEndFactor:1.3 aMid:60° rMidFactor:1.6 extendLimitFactor:11 ...]
47 someBrace: [heightBrace height:4mm ...]
50 closedBrace: \ p0 p1 height width:void →
52   lowHeight: height - [if [typeof width]=§Void @width width]
53   lowBrace:  [reverse [genericBrace p0 p1 aEnd:70° rEndFactor:1.3 aMid:55° rMidFactor:1.6 extendLimitFactor:11 height:lowHeight]]
54   highBrace:          [genericBrace p0 p1 aEnd:80° rEndFactor:1.3 aMid:50° rMidFactor:1.6 extendLimitFactor:11 height:height]
55   lowBrace--highBrace--cycle
58 someClosedBrace: [closedBrace height:5mm ...]