Arc.ts
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* 圆弧
*/
import Path, { PathProps } from '../Path';
export class ArcShape {
cx = 0;
cy = 0;
r = 0;
startAngle = 0;
endAngle = Math.PI * 2
clockwise? = true
}
export interface ArcProps extends PathProps {
shape?: Partial<ArcShape>
}
class Arc extends Path<ArcProps> {
shape: ArcShape
constructor(opts?: ArcProps) {
super(opts);
}
getDefaultStyle() {
return {
stroke: '#000',
fill: null as string
};
}
getDefaultShape() {
return new ArcShape();
}
buildPath(ctx: CanvasRenderingContext2D, shape: ArcShape) {
const x = shape.cx;
const y = shape.cy;
const r = Math.max(shape.r, 0);
const startAngle = shape.startAngle;
const endAngle = shape.endAngle;
const clockwise = shape.clockwise;
const unitX = Math.cos(startAngle);
const unitY = Math.sin(startAngle);
ctx.moveTo(unitX * r + x, unitY * r + y);
ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
}
}
Arc.prototype.type = 'arc';
export default Arc;