public SpatialRelation Relate(Point point)
{
if (point.GetY() > GetMaxY() || point.GetY() < GetMinY())
return SpatialRelation.DISJOINT;
// all the below logic is rather unfortunate but some dateline cases demand it
double minX = this.minX;
double maxX = this.maxX;
double pX = point.GetX();
if (ctx.IsGeo())
{
//unwrap dateline and normalize +180 to become -180
double rawWidth = maxX - minX;
if (rawWidth < 0)
{
maxX = minX + (rawWidth + 360);
}
//shift to potentially overlap
if (pX < minX)
{
pX += 360;
}
else if (pX > maxX)
{
pX -= 360;
} else {
return SpatialRelation.CONTAINS; //short-circuit
}
}
if (pX < minX || pX > maxX)
return SpatialRelation.DISJOINT;
return SpatialRelation.CONTAINS;
}