localBounds method

Rect2D localBounds()

Conservative source-space AABB from endpoints and curve controls.

Implementation

Rect2D localBounds() {
  if (cmds.isEmpty) return const Rect2D(0, 0, 0, 0);
  double minX = double.infinity, minY = double.infinity;
  double maxX = -double.infinity, maxY = -double.infinity;
  void acc(Vec2 v) {
    if (v.x < minX) minX = v.x;
    if (v.x > maxX) maxX = v.x;
    if (v.y < minY) minY = v.y;
    if (v.y > maxY) maxY = v.y;
  }

  for (final c in cmds) {
    switch (c.verb) {
      case PathVerb.moveTo:
      case PathVerb.lineTo:
        acc(c.p);
        break;
      case PathVerb.quadTo:
        acc(c.p);
        acc(c.c1!);
        break;
      case PathVerb.cubicTo:
        acc(c.p);
        acc(c.c1!);
        acc(c.c2!);
        break;
      case PathVerb.close:
        break;
    }
  }
  return Rect2D.fromLTRB(minX, minY, maxX, maxY);
}