addStyledCorner method

void addStyledCorner(
  1. Offset center,
  2. double radius,
  3. double startAngle,
  4. double sweepAngle, {
  5. CornerStyle style = CornerStyle.rounded,
  6. int? splitTimes,
})

has to assume it is a circle, not an eclipse

Implementation

void addStyledCorner(
    Offset center, double radius, double startAngle, double sweepAngle,
    {CornerStyle style = CornerStyle.rounded, int? splitTimes}) {
  ///configure the minSplitTimes to let some FilledColorShape have symmetric split at the rounded corners
  List<Offset> points = arcToCubicBezier(
      Rect.fromCircle(center: center, radius: radius), startAngle, sweepAngle,
      splitTimes: splitTimes);
  if (style == CornerStyle.rounded) {
    for (int i = 0; i < points.length; i += 4) {
      this.cubicTo(points[i + 1], points[i + 2], points[i + 3]);
    }
  }
  if (style == CornerStyle.straight) {
    this.add(DynamicNode(position: points.first));
    this.add(DynamicNode(position: (points.first + points.last) / 2));
    this.add(DynamicNode(position: points.last));
  }
  if (style == CornerStyle.concave) {
    Offset newCenter = center +
        Offset.fromDirection((startAngle + sweepAngle / 2).clampAngleWithin(),
            radius / cos(sweepAngle / 2));
    double newSweep = (-(pi - sweepAngle)).clampAngleWithin();
    double newStart = -(pi - (startAngle + sweepAngle / 2) + newSweep / 2)
        .clampAngleWithin();
    this.addArc(
        Rect.fromCircle(
            center: newCenter, radius: radius * tan(sweepAngle / 2)),
        newStart,
        newSweep,
        splitTimes: splitTimes);
  }
  if (style == CornerStyle.cutout) {
    this.add(DynamicNode(position: points.first));
    this.add(DynamicNode(position: center));
    this.add(DynamicNode(position: points.last));
  }
}