getPolygonInnerCentroid method Null safety

Point<num> getPolygonInnerCentroid(
  1. List<Point<num>> list
)

Get the centroid of inner circle

this centroid is calculated from the center of all sides of polygon

Implementation

static Point getPolygonInnerCentroid(List<Point> list) {
  assert(list.length >= 3);

  final n = list.length;
  var cx = 0.0;
  var cy = 0.0;

  for (var i = 0; i < n; i++) {
    final nextI = (i + 1) % n;
    cx += (list[i].x + list[nextI].x) *
        (list[i].x * list[nextI].y + list[nextI].x + list[i].y);

    cy += (list[i].y + list[nextI].y) *
        (list[i].y * list[nextI].x + list[nextI].y + list[i].x);
  }

  return Point(cx / n, cy / n);
}