|
1 | 1 | import { PathRebuilder } from 'zrender/lib/core/PathProxy';
|
2 | 2 | import { SkPath, Skia } from '@shopify/react-native-skia';
|
| 3 | +import { isAroundZero } from './helper'; |
3 | 4 |
|
| 5 | +const PI = Math.PI; |
| 6 | +const PI2 = Math.PI * 2; |
4 | 7 | export default class SkiaPathRebuilder implements PathRebuilder {
|
5 | 8 | private path: SkPath;
|
6 | 9 |
|
@@ -50,24 +53,41 @@ export default class SkiaPathRebuilder implements PathRebuilder {
|
50 | 53 | rotation: number,
|
51 | 54 | startAngle: number,
|
52 | 55 | endAngle: number,
|
53 |
| - counterclockwise: boolean = false |
| 56 | + anticlockwise: boolean = false |
54 | 57 | ) {
|
55 |
| - const useSmallArc = Math.abs(endAngle - startAngle) <= Math.PI; |
| 58 | + let dTheta = endAngle - startAngle; |
| 59 | + const clockwise = !anticlockwise; |
| 60 | + |
| 61 | + const dThetaPositive = Math.abs(dTheta); |
| 62 | + const isCircle = |
| 63 | + isAroundZero(dThetaPositive - PI2) || |
| 64 | + (clockwise ? dTheta >= PI2 : -dTheta >= PI2); |
| 65 | + |
| 66 | + const useSmallArc = Math.abs(endAngle - startAngle) <= PI; |
56 | 67 |
|
57 | 68 | const endX = x + radiusX * Math.cos(endAngle);
|
58 | 69 | const endY = y + radiusY * Math.sin(endAngle);
|
59 | 70 |
|
60 |
| - const xAxisRotateInDegrees = (rotation * 180) / Math.PI; |
61 |
| - |
62 |
| - this.path.arcToRotated( |
63 |
| - radiusX, |
64 |
| - radiusY, |
65 |
| - xAxisRotateInDegrees, |
66 |
| - useSmallArc, |
67 |
| - counterclockwise, |
68 |
| - endX, |
69 |
| - endY |
70 |
| - ); |
| 71 | + const xAxisRotateInDegrees = (rotation * 180) / PI; |
| 72 | + if (isCircle) { |
| 73 | + const ovalRect = { |
| 74 | + x: x - radiusX, |
| 75 | + y: y - radiusY, |
| 76 | + width: radiusX * 2, |
| 77 | + height: radiusY * 2, |
| 78 | + }; |
| 79 | + this.path.addOval(ovalRect, anticlockwise); |
| 80 | + } else { |
| 81 | + this.path.arcToRotated( |
| 82 | + radiusX, |
| 83 | + radiusY, |
| 84 | + xAxisRotateInDegrees, |
| 85 | + useSmallArc, |
| 86 | + anticlockwise, |
| 87 | + endX, |
| 88 | + endY |
| 89 | + ); |
| 90 | + } |
71 | 91 | }
|
72 | 92 |
|
73 | 93 | rect(x: number, y: number, width: number, height: number): void {
|
|
0 commit comments