/**
   * Called after bounding box is intersected.
   *
   * @param bboxSect INTERSECTS or CONTAINS from enclosingBox's intersection
   * @return DISJOINT, CONTAINS, or INTERSECTS (not WITHIN)
   */
  @Override
  protected SpatialRelation relateRectanglePhase2(Rectangle r, SpatialRelation bboxSect) {

    // Rectangle wraps around the world longitudinally creating a solid band; there are no corners
    // to test intersection
    if (r.getWidth() == 360) {
      return SpatialRelation.INTERSECTS;
    }

    if (inverseCircle != null) {
      return inverseCircle.relate(r).inverse();
    }

    // if a pole is wrapped, we have a separate algorithm
    if (enclosingBox.getWidth() == 360) {
      return relateRectangleCircleWrapsPole(r, ctx);
    }

    // This is an optimization path for when there are no dateline or pole issues.
    if (!enclosingBox.getCrossesDateLine() && !r.getCrossesDateLine()) {
      return super.relateRectanglePhase2(r, bboxSect);
    }

    // do quick check to see if all corners are within this circle for CONTAINS
    int cornersIntersect = numCornersIntersect(r);
    if (cornersIntersect == 4) {
      // ensure r's x axis is within c's.  If it doesn't, r sneaks around the globe to touch the
      // other side (intersect).
      SpatialRelation xIntersect = r.relateXRange(enclosingBox.getMinX(), enclosingBox.getMaxX());
      if (xIntersect == SpatialRelation.WITHIN) return SpatialRelation.CONTAINS;
      return SpatialRelation.INTERSECTS;
    }

    // INTERSECT or DISJOINT ?
    if (cornersIntersect > 0) return SpatialRelation.INTERSECTS;

    // Now we check if one of the axis of the circle intersect with r.  If so we have
    // intersection.

    /* x axis intersects  */
    if (r.relateYRange(getYAxis(), getYAxis()).intersects() // at y vertical
        && r.relateXRange(enclosingBox.getMinX(), enclosingBox.getMaxX()).intersects())
      return SpatialRelation.INTERSECTS;

    /* y axis intersects */
    if (r.relateXRange(getXAxis(), getXAxis()).intersects()) { // at x horizontal
      double yTop = getCenter().getY() + radiusDEG;
      assert yTop <= 90;
      double yBot = getCenter().getY() - radiusDEG;
      assert yBot >= -90;
      if (r.relateYRange(yBot, yTop).intersects()) // back bottom
      return SpatialRelation.INTERSECTS;
    }

    return SpatialRelation.DISJOINT;
  }