center method

LocationPoint center()

Implementation

LocationPoint center() {
  if (!this.isValid()) {
    return LocationPoint();
  } else {
    num xsum = 0.0;
    num ysum = 0.0;
    num perim = 0.0;

    for (int i = 0; i < this.points.length; ++i) {
      LocationPoint p = this.points[i];
      LocationPoint q = this.points[(i + 1) % this.points.length];
      num length = p.distanceTo(q);
      perim += length;
      xsum += (p.x + q.x) * length / 2.0;
      ysum += (p.y + q.y) * length / 2.0;
    }

    return perim > 1.0E-8
        ? LocationPoint.fromData(
            this.location, this.subLocation, xsum / perim, ysum / perim)
        : LocationPoint.fromLocationPoint(this.points[0]);
  }
}