addOval method

PathBuilder addOval(
  1. Rect oval
)

Adds an oval command to new path.

Implementation

PathBuilder addOval(Rect oval) {
  final Point r = Point(oval.width * 0.5, oval.height * 0.5);
  final Point c = Point(
    oval.left + (oval.width * 0.5),
    oval.top + (oval.height * 0.5),
  );
  final Point m = Point(
    _kArcApproximationMagic * r.x,
    _kArcApproximationMagic * r.y,
  );

  moveTo(c.x, c.y - r.y);

  // Top right arc.
  cubicTo(c.x + m.x, c.y - r.y, c.x + r.x, c.y - m.y, c.x + r.x, c.y);

  // Bottom right arc.
  cubicTo(c.x + r.x, c.y + m.y, c.x + m.x, c.y + r.y, c.x, c.y + r.y);

  // Bottom left arc.
  cubicTo(c.x - m.x, c.y + r.y, c.x - r.x, c.y + m.y, c.x - r.x, c.y);

  // Top left arc.
  cubicTo(c.x - r.x, c.y - m.y, c.x - m.x, c.y - r.y, c.x, c.y - r.y);

  close();
  return this;
}