drawOval method
Draw an oval inscribed in a rectangle.
Equivalent to PyMuPDF's shape.draw_oval().
Implementation
Point drawOval(Rect rect) {
// Approximate ellipse with 4 cubic Bezier curves
final cx = (rect.x0 + rect.x1) / 2;
final cy = (rect.y0 + rect.y1) / 2;
final rx = rect.width / 2;
final ry = rect.height / 2;
// kappa for circle approximation
const k = 0.5522847498;
final kx = rx * k;
final ky = ry * k;
// Start at right-middle
_path.write('${_f(cx + rx)} ${_f(cy)} m ');
// Top-right quarter
_path.write(
'${_f(cx + rx)} ${_f(cy - ky)} '
'${_f(cx + kx)} ${_f(cy - ry)} '
'${_f(cx)} ${_f(cy - ry)} c ',
);
// Top-left quarter
_path.write(
'${_f(cx - kx)} ${_f(cy - ry)} '
'${_f(cx - rx)} ${_f(cy - ky)} '
'${_f(cx - rx)} ${_f(cy)} c ',
);
// Bottom-left quarter
_path.write(
'${_f(cx - rx)} ${_f(cy + ky)} '
'${_f(cx - kx)} ${_f(cy + ry)} '
'${_f(cx)} ${_f(cy + ry)} c ',
);
// Bottom-right quarter (close)
_path.write(
'${_f(cx + kx)} ${_f(cy + ry)} '
'${_f(cx + rx)} ${_f(cy + ky)} '
'${_f(cx + rx)} ${_f(cy)} c ',
);
_pathOps++;
_lastPoint = Point(cx + rx, cy);
return _lastPoint!;
}