UNPKG

1.01 kBJavaScriptView Raw
1var Shape = require('./generic');
2
3module.exports = Shape(function(innerRadius, outerRadius, startAngle, endAngle){
4
5 var circle = Math.PI * 2,
6 radiansPerDegree = Math.PI / 180,
7 sa = startAngle * radiansPerDegree % circle || 0,
8 ea = endAngle * radiansPerDegree % circle || 0,
9 ir = Math.min(innerRadius || 0, outerRadius || 0),
10 or = Math.max(innerRadius || 0, outerRadius || 0),
11 a = sa > ea ? circle - sa + ea : ea - sa;
12
13 this.width = this.height = or * 2;
14 var path = this.path;
15
16 if (a >= circle){
17
18 path.move(0, or).arc(or * 2, 0, or).arc(-or * 2, 0, or);
19 if (ir) path.move(or - ir, 0).counterArc(ir * 2, 0, ir).counterArc(-ir * 2, 0, ir);
20
21 } else {
22
23 var ss = Math.sin(sa), es = Math.sin(ea),
24 sc = Math.cos(sa), ec = Math.cos(ea),
25 ds = es - ss, dc = ec - sc, dr = ir - or,
26 large = a > Math.PI;
27
28 path.move(or + or * ss, or - or * sc).arc(or * ds, or * -dc, or, or, large).line(dr * es, dr * -ec);
29 if (ir) path.counterArc(ir * -ds, ir * dc, ir, ir, large);
30
31 }
32
33 path.close();
34
35});
\No newline at end of file