public boolean tryAddPoint(int x, int y) {
    if (type!=TYPE_POLY) return false;
    double minDist=Line2D.ptSegDist((double)poly.xpoints[poly.npoints-1], (double)poly.ypoints[poly.npoints-1],
                          (double)poly.xpoints[0], (double)poly.ypoints[0],
                          (double)x, (double)y);
    int minPoint=poly.npoints-1;
    for (int i=1; i<poly.npoints; i++) {
      double l=Line2D.ptSegDist((double)poly.xpoints[i-1], (double)poly.ypoints[i-1],
                                (double)poly.xpoints[i], (double)poly.ypoints[i],
                                (double)x, (double)y);
      if (l<minDist) {
        minDist=l;
        minPoint=i-1;
      }
    }

    if (minDist<10.0) {
      insertPoint(minPoint, x, y);
      return true;
    }

    return false;
  }