sector static method
A sector path function.
This functions can either return a new path or add to existing path
.
Implementation
static Path sector({
required Offset center,
required double r,
required double r0,
required double startAngle,
required double endAngle,
required bool clockwise,
Path? path,
}) {
path = path ?? Path();
final sweepAngle =
clockwise ? endAngle - startAngle : startAngle - endAngle;
if (sweepAngle.equalTo(0)) {
return path;
}
// The canvas can not fill a ring, so it is devided to two semi rings
if (sweepAngle.abs().equalTo(pi * 2)) {
sector(
center: center,
r: r,
r0: r0,
startAngle: 0,
endAngle: pi,
clockwise: true,
path: path,
);
sector(
center: center,
r: r,
r0: r0,
startAngle: pi,
endAngle: pi * 2,
clockwise: true,
path: path,
);
return path;
}
path.moveTo(
cos(startAngle) * r + center.dx, sin(startAngle) * r + center.dy);
path.arcTo(
Rect.fromCircle(center: center, radius: r),
startAngle,
sweepAngle,
false,
);
path.lineTo(cos(endAngle) * r0 + center.dx, sin(endAngle) * r0 + center.dy);
if (r0 != 0) {
path.arcTo(
Rect.fromCircle(center: center, radius: r0),
endAngle,
-sweepAngle,
false,
);
}
path.close();
return path;
}