bool MyPtInRect(Point2d pCur, Point2d pLeftTop, Point2d pRightTop, Point2d pRightBelow, Point2d pLeftBelow)
{
int nCount = 4;
Point2d RectPoints[4] = { pLeftTop, pLeftBelow, pRightBelow, pRightTop };
int nCross = 0;
double lastPointX = -999.999;
for (int i = 0; i < nCount; i++)
{
Point2d pBegin = RectPoints[i];
Point2d pEnd = RectPoints[(i + 1) % nCount];
if (pBegin.y == pEnd.y)continue;
if (pCur.y < min(pBegin.y, pEnd.y) || pCur.y > max(pBegin.y, pEnd.y))continue;
double x = (double)(pCur.y - pBegin.y) * (double)(pEnd.x - pBegin.x) / (double)(pEnd.y - pBegin.y) + pBegin.x;
if (x > pCur.x)
{
if (x != lastPointX)
{
nCross++;
lastPointX = x;
}
}
}
return (nCross % 2 == 1);
}