mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:20:06 +00:00
Change IsPointInPolygon to check polygon with equal points correctly
This commit is contained in:
parent
0043283881
commit
e43c0594d1
1 changed files with 9 additions and 0 deletions
|
|
@ -47,6 +47,7 @@ bool IsPointInPolygon(const std::vector<glm::vec2>& vertices,
|
||||||
const glm::vec2& point)
|
const glm::vec2& point)
|
||||||
{
|
{
|
||||||
bool inPolygon = true;
|
bool inPolygon = true;
|
||||||
|
bool allSame = true;
|
||||||
|
|
||||||
// For each vertex, assume counterclockwise order
|
// For each vertex, assume counterclockwise order
|
||||||
for (std::size_t i = 0; i < vertices.size(); ++i)
|
for (std::size_t i = 0; i < vertices.size(); ++i)
|
||||||
|
|
@ -55,6 +56,8 @@ bool IsPointInPolygon(const std::vector<glm::vec2>& vertices,
|
||||||
const auto& p2 =
|
const auto& p2 =
|
||||||
(i == vertices.size() - 1) ? vertices[0] : vertices[i + 1];
|
(i == vertices.size() - 1) ? vertices[0] : vertices[i + 1];
|
||||||
|
|
||||||
|
allSame = allSame && p1.x == p2.x && p1.y == p2.y;
|
||||||
|
|
||||||
// Test which side of edge point lies on
|
// Test which side of edge point lies on
|
||||||
const float a = -(p2.y - p1.y);
|
const float a = -(p2.y - p1.y);
|
||||||
const float b = p2.x - p1.x;
|
const float b = p2.x - p1.x;
|
||||||
|
|
@ -70,6 +73,12 @@ bool IsPointInPolygon(const std::vector<glm::vec2>& vertices,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allSame)
|
||||||
|
{
|
||||||
|
inPolygon = vertices.size() > 0 && vertices[0].x == point.x &&
|
||||||
|
vertices[0].y == point.y;
|
||||||
|
}
|
||||||
|
|
||||||
return inPolygon;
|
return inPolygon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue