class OsmNogoPolygon extends OsmNodeNamed {

  public void calcBoundingCircle()
  {
    int cxmin, cxmax, cymin, cymax;
    cxmin = cymin = Integer.MAX_VALUE;
    cxmax = cymax = Integer.MIN_VALUE;

    // first calculate a starting center point as center of boundingbox
    for (int i = 0; i < points.size(); i++)
    {
      final Point p = points.get(i);
      if (p.x < cxmin)
      {
        cxmin = p.x;
      }
      if (p.x > cxmax)
      {
        cxmax = p.x;
      }
      if (p.y < cymin)
      {
        cymin = p.y;
      }
      if (p.y > cymax)
      {
        cymax = p.y;
      }
    }

    int cx = (cxmax+cxmin) / 2; // center of circle
    int cy = (cymax+cymin) / 2;

    double[] lonlat2m = CheapRuler.getLonLatToMeterScales( cy );
    double dlon2m = lonlat2m[0];
    double dlat2m = lonlat2m[1];

    double rad = 0;  // radius

    double dmax = 0; // length of vector from center to point
    int i_max = -1;

    do
    {
      // now identify the point outside of the circle that has the greatest distance
      for (int i = 0; i < points.size(); i++)
      {
        final Point p = points.get(i);
        final double dist = CheapRuler.distance(p.x, p.y, (int) cx, (int) cy);
        if (dist <= rad)
        {
          continue;
        }
        if (dist > dmax)
        {
          // new maximum distance found
          dmax = dist;
          i_max = i;
        }
      }
      if (i_max < 0)
      {
    	  break; // leave loop when no point outside the circle is found any more.
      }
      final double dd = 0.5 * (1 - rad / dmax);

      final Point p = points.get(i_max); // calculate new radius to just include this point
      cx += (int)(dd * (p.x - cx) + 0.5); // shift center toward point
      cy += (int)(dd * (p.y - cy) + 0.5);

      dmax = rad = CheapRuler.distance(p.x, p.y, (int) cx, (int) cy);
      i_max = -1;
    }
    while (true);

    ilon = cx;
    ilat = cy;
    radius = rad;
    return;
  }

  public  OsmNogoPolygon(boolean closed);

}