1 | var Shape = require('./generic');
|
2 |
|
3 | module.exports = Shape(function(width, height, radius){
|
4 |
|
5 | this.width = width;
|
6 | this.height = height;
|
7 |
|
8 | var path = this.path;
|
9 |
|
10 | if (!radius){
|
11 |
|
12 | path.move(0, 0).line(width, 0).line(0, height).line(-width, 0).line(0, -height);
|
13 |
|
14 | } else {
|
15 |
|
16 | if (typeof radius == 'number') radius = [radius, radius, radius, radius];
|
17 |
|
18 | var tl = radius[0], tr = radius[1], br = radius[2], bl = radius[3];
|
19 |
|
20 | if (tl < 0) tl = 0;
|
21 | if (tr < 0) tr = 0;
|
22 | if (bl < 0) bl = 0;
|
23 | if (br < 0) br = 0;
|
24 |
|
25 | path.move(0, tl);
|
26 |
|
27 | if (width < 0) path.move(width, 0);
|
28 | if (height < 0) path.move(0, height);
|
29 |
|
30 | if (tl > 0) path.arc(tl, -tl);
|
31 | path.line(Math.abs(width) - (tr + tl), 0);
|
32 |
|
33 | if (tr > 0) path.arc(tr, tr);
|
34 | path.line(0, Math.abs(height) - (tr + br));
|
35 |
|
36 | if (br > 0) path.arc(-br, br);
|
37 | path.line(- Math.abs(width) + (br + bl), 0);
|
38 |
|
39 | if (bl > 0) path.arc(-bl, -bl);
|
40 | path.line(0, - Math.abs(height) + (bl + tl));
|
41 | }
|
42 |
|
43 | path.close();
|
44 |
|
45 | }); |
\ | No newline at end of file |