我的大脑今天不工作了。我需要测试一个点(纬度,经度)是否位于地图上的一个矩形内。矩形由它的北、东、南和西边界定义。打嗝是所有点或值都在地图坐标系中。为了处理日期线环绕,我假设如果我们从左到右,经度总是“介于”之间。
bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
// ????
}
假设东和北为正:
bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
// you may want to check that the point is a valid coordinate
if (West < East)
{
return pt.X < East && pt.X > West && pt.Y < North && pt.Y > South;
}
// it crosses the date line
return (pt.X < East || pt.X > West) && pt.Y < North && pt.Y > South;
}