MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / insidePolygon

Method insidePolygon

src/Geoscape/Globe.cpp:509–539  ·  view source on GitHub ↗

* Checks if a polar point is inside a certain polygon. * @param lon Longitude of the point. * @param lat Latitude of the point. * @param poly Pointer to the polygon. * @return True if it's inside, False if it's outside. */

Source from the content-addressed store, hash-verified

507 * @return True if it's inside, False if it's outside.
508 */
509bool Globe::insidePolygon(double lon, double lat, Polygon *poly) const
510{
511 bool backFace = true;
512 for (int i = 0; i < poly->getPoints(); ++i)
513 {
514 backFace = backFace && pointBack(poly->getLongitude(i), poly->getLatitude(i));
515 }
516 if (backFace != pointBack(lon, lat))
517 return false;
518
519 bool odd = false;
520 for (int i = 0; i < poly->getPoints(); ++i)
521 {
522 int j = (i + 1) % poly->getPoints();
523
524 /*double x = lon, y = lat,
525 x_i = poly->getLongitude(i), y_i = poly->getLatitude(i),
526 x_j = poly->getLongitude(j), y_j = poly->getLatitude(j);*/
527
528 double x, y, x_i, x_j, y_i, y_j;
529 polarToCart(poly->getLongitude(i), poly->getLatitude(i), &x_i, &y_i);
530 polarToCart(poly->getLongitude(j), poly->getLatitude(j), &x_j, &y_j);
531 polarToCart(lon, lat, &x, &y);
532
533 if (((y_i < y && y_j >= y) || (y_j < y && y_i >= y)) && (x_i <= x || x_j <= x))
534 {
535 odd ^= (x_i + (y - y_i) / (y_j - y_i) * (x_j - x_i) < x);
536 }
537 }
538 return odd;
539}
540
541/**
542 * Loads a series of map polar coordinates in X-Com format,

Callers

nothing calls this directly

Calls 3

getPointsMethod · 0.45
getLongitudeMethod · 0.45
getLatitudeMethod · 0.45

Tested by

no test coverage detected