216 } |
215 } |
217 |
216 |
218 bool isConvex(const std::vector<glm::vec3>& polygon) |
217 bool isConvex(const std::vector<glm::vec3>& polygon) |
219 { |
218 { |
220 const std::size_t n = polygon.size(); |
219 const std::size_t n = polygon.size(); |
221 auto polygonRing = iter::ring(polygon, n); |
|
222 std::vector<glm::vec3> crosses; |
220 std::vector<glm::vec3> crosses; |
223 crosses.resize(n); |
221 crosses.resize(n); |
224 for (std::size_t i = 0; i < n; i += 1) |
222 for (std::size_t i = 0; i < n; i += 1) |
225 { |
223 { |
226 crosses[i] = glm::cross(polygonRing[i - 1] - polygonRing[i], polygonRing[i + 1] - polygonRing[i]); |
224 const glm::vec3 v1 = polygon[(i + n - 1) % n]; |
|
225 const glm::vec3 v2 = polygon[i]; |
|
226 const glm::vec3 v3 = polygon[(i + 1) % n]; |
|
227 crosses[i] = glm::cross(v1 - v2, v3 - v2); |
227 } |
228 } |
228 return not std::any_of( |
229 return not std::any_of( |
229 crosses.begin() + 1, |
230 crosses.begin() + 1, |
230 crosses.end(), |
231 crosses.end(), |
231 [&crosses](const glm::vec3& vector) |
232 [&crosses](const glm::vec3& vector) |