compute method

void compute()

Implementation

void compute() {
  // Priority queue of cells, ordered by maximum distance from boundary
  PriorityQueue cellQueue = PriorityQueue();

  createInitialGrid(inputGeom.getEnvelopeInternal(), cellQueue);

  // initial candidate center point
  CellMIC farthestCell = createInterorPointCell(inputGeom);
  //int totalCells = cellQueue.size();

  /**
   * Carry out the branch-and-bound search
   * of the cell space
   */
  int maxIter = computeMaximumIterations(inputGeom, tolerance);
  int iter = 0;
  while (! cellQueue.isEmpty() && iter < maxIter) {
    iter++;
    // pick the most promising cell from the queue
    CellMIC cell = cellQueue.poll() as CellMIC;

    //System.out.println(factory.toGeometry(cell.getEnvelope()));
    //System.out.println(iter + "] Dist: " + cell.getDistance() + " Max D: " + cell.getMaxDistance() + " size: " + cell.getHSide());
    //TestBuilderProxy.showIndicator(inputGeom.getFactory().toGeometry(cell.getEnvelope()));

    //-- if cell must be closer than furthest, terminate since all remaining cells in queue are even closer.
    if (cell.getMaxDistance() < farthestCell.getDistance())
      break;

    // update the circle center cell if the candidate is further from the boundary
    if (cell.getDistance() > farthestCell.getDistance()) {
      farthestCell = cell;
    }
    /**
     * Refine this cell if the potential distance improvement
     * is greater than the required tolerance.
     * Otherwise the cell is pruned (not investigated further),
     * since no point in it is further than
     * the current farthest distance.
     */
    double potentialIncrease = cell.getMaxDistance() - farthestCell.getDistance();
    if (potentialIncrease > tolerance) {
      // split the cell into four sub-cells
      double h2 = cell.getHSide() / 2;
      cellQueue.add( createCell( cell.getX() - h2, cell.getY() - h2, h2));
      cellQueue.add( createCell( cell.getX() + h2, cell.getY() - h2, h2));
      cellQueue.add( createCell( cell.getX() - h2, cell.getY() + h2, h2));
      cellQueue.add( createCell( cell.getX() + h2, cell.getY() + h2, h2));
      //totalCells += 4;
    }
  }
  // the farthest cell is the best approximation to the MIC center
  centerCell = farthestCell;
  centerPt = new Coordinate(centerCell.getX(), centerCell.getY());
  centerPoint = factory.createPoint(centerPt);
  // compute radius point
  List<Coordinate?>? nearestPts = indexedDistance.nearestPointsToGeometry(centerPoint);
  if(nearestPts != null) {
    radiusPt = nearestPts[0]!.copy();
    radiusPoint = factory.createPoint(radiusPt);
  }
}