You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bool Intersection::pointInPolygon(const cocos2d::Vec2& pos, const std::vectorcocos2d::Vec2& polygon)
{
bool inside = false;
auto x = pos.x;
auto y = pos.y;
// use some raycasting to test hits
// https://github.com/substack/point-in-polygon/blob/master/index.js
auto length = polygon.size();
bool intersect = false;
for (size_t i = 0, j = length-1; i < length; j = i++)
{
auto xi = polygon[i].x, yi = polygon[i].y,
xj = polygon[j].x, yj = polygon[j].y;
intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect)
inside = !inside;
}
return inside;
}
The text was updated successfully, but these errors were encountered:
bool Intersection::pointInPolygon(const cocos2d::Vec2& pos, const std::vectorcocos2d::Vec2& polygon)
{
bool inside = false;
auto x = pos.x;
auto y = pos.y;
}
The text was updated successfully, but these errors were encountered: