public static bool Contains(int[] xPoints, int[] yPoints, int nPoints, RectBox bounds, int x1, int y1) { if ((bounds != null && bounds.Inside(x1, y1)) || (bounds == null && GetBoundingBox(xPoints, yPoints, nPoints) .Inside(x1, y1))) { int hits = 0; int ySave = 0; int i = 0; while (i < nPoints && yPoints[i] == y1) { i++; } for (int n = 0; n < nPoints; n++) { int j = (i + 1) % nPoints; int dx = xPoints[j] - xPoints[i]; int dy = yPoints[j] - yPoints[i]; if (dy != 0) { int rx = x1 - xPoints[i]; int ry = y1 - yPoints[i]; if (yPoints[j] == y1 && xPoints[j] >= x1) { ySave = yPoints[i]; } if (yPoints[i] == y1 && xPoints[i] >= x1) { if ((ySave > y1) != (yPoints[j] > y1)) { hits--; } } if (ry * dy >= 0 && (ry <= dy && ry >= 0 || ry >= dy && ry <= 0) && Round(dx * ry, dy) >= rx) { hits++; } } i = j; } return((hits % 2) != 0); } return(false); }