protected override 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 base.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;
Debug.Assert(yTop <= 90);
double yBot = GetCenter().GetY() - radiusDEG;
Debug.Assert(yBot >= -90);
if (r.RelateYRange(yBot, yTop).Intersects())//back bottom
return SpatialRelation.INTERSECTS;
}
return SpatialRelation.DISJOINT;
}