(ctx: CanvasRenderingContext2D, element: ArcElement, endAngle: number)
| 5 | import type {ArcOptions, Point} from '../types/index.js'; |
| 6 | |
| 7 | function clipSelf(ctx: CanvasRenderingContext2D, element: ArcElement, endAngle: number) { |
| 8 | const {startAngle, x, y, outerRadius, innerRadius, options} = element; |
| 9 | const {borderWidth, borderJoinStyle} = options; |
| 10 | const outerAngleClip = Math.min(borderWidth / outerRadius, _normalizeAngle(startAngle - endAngle)); |
| 11 | ctx.beginPath(); |
| 12 | ctx.arc(x, y, outerRadius - borderWidth / 2, startAngle + outerAngleClip / 2, endAngle - outerAngleClip / 2); |
| 13 | |
| 14 | if (innerRadius > 0) { |
| 15 | const innerAngleClip = Math.min(borderWidth / innerRadius, _normalizeAngle(startAngle - endAngle)); |
| 16 | ctx.arc(x, y, innerRadius + borderWidth / 2, endAngle - innerAngleClip / 2, startAngle + innerAngleClip / 2, true); |
| 17 | } else { |
| 18 | const clipWidth = Math.min(borderWidth / 2, outerRadius * _normalizeAngle(startAngle - endAngle)); |
| 19 | |
| 20 | if (borderJoinStyle === 'round') { |
| 21 | ctx.arc(x, y, clipWidth, endAngle - PI / 2, startAngle + PI / 2, true); |
| 22 | } else if (borderJoinStyle === 'bevel') { |
| 23 | const r = 2 * clipWidth * clipWidth; |
| 24 | const endX = -r * Math.cos(endAngle + PI / 2) + x; |
| 25 | const endY = -r * Math.sin(endAngle + PI / 2) + y; |
| 26 | const startX = r * Math.cos(startAngle + PI / 2) + x; |
| 27 | const startY = r * Math.sin(startAngle + PI / 2) + y; |
| 28 | ctx.lineTo(endX, endY); |
| 29 | ctx.lineTo(startX, startY); |
| 30 | } |
| 31 | } |
| 32 | ctx.closePath(); |
| 33 | |
| 34 | ctx.moveTo(0, 0); |
| 35 | ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 36 | |
| 37 | ctx.clip('evenodd'); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | function clipArc(ctx: CanvasRenderingContext2D, element: ArcElement, endAngle: number) { |
no test coverage detected