centerPoint property

  1. @override
Coordinates get centerPoint
override

Retrieves the center point of the geographic area. Calculates and returns the geographic center of the area.

Returns

  • Coordinates object representing the center point of the area.

Implementation

@override
Coordinates get centerPoint {
  final int nVecs = coordinates.length;

  if (nVecs < 3) {
    return Coordinates();
  }

  double ai, atmp = 0, xtmp = 0, ytmp = 0;

  int i = nVecs - 1;
  int j = 0;

  while (j < nVecs) {
    final Coordinates ci = coordinates[i];
    final Coordinates cj = coordinates[j];

    ai = _crossProductScalarValue(
      ci.longitude,
      ci.latitude,
      cj.longitude,
      cj.latitude,
    );
    atmp += ai;

    xtmp += (cj.longitude + ci.longitude) * ai;
    ytmp += (cj.latitude + ci.latitude) * ai;

    i = j++;
  }

  if (atmp == 0) {
    return Coordinates();
  }

  return Coordinates(
    longitude: xtmp / (3 * atmp),
    latitude: ytmp / (3 * atmp),
  );
}