src/geometry.cpp

changeset 223
ce81db996275
parent 206
654661eab7f3
child 250
2837b549e616
equal deleted inserted replaced
222:72b456f2f3c2 223:ce81db996275
197 glm::vec2{rectangle.right(), rectangle.top()}, 197 glm::vec2{rectangle.right(), rectangle.top()},
198 glm::vec2{rectangle.right(), rectangle.bottom()} 198 glm::vec2{rectangle.right(), rectangle.bottom()}
199 }; 199 };
200 } 200 }
201 201
202 bool isConvex(const Quadrilateral& quad)
203 {
204 glm::vec3 crosses[4] = {
205 glm::cross(quad.p4 - quad.p1, quad.p2 - quad.p1),
206 glm::cross(quad.p1 - quad.p2, quad.p3 - quad.p2),
207 glm::cross(quad.p2 - quad.p3, quad.p4 - quad.p3),
208 glm::cross(quad.p3 - quad.p4, quad.p1 - quad.p4),
209 };
210 return not std::any_of(
211 &crosses[1],
212 &crosses[4],
213 [&crosses](const glm::vec3& vector) {
214 return glm::dot(crosses[0], vector) < 1e-6;
215 });
216 }
217
202 bool isConvex(const std::vector<glm::vec3>& polygon) 218 bool isConvex(const std::vector<glm::vec3>& polygon)
203 { 219 {
204 const int n = polygon.size(); 220 const int n = polygon.size();
205 auto polygonRing = iter::ring(polygon, n); 221 auto polygonRing = iter::ring(polygon, n);
206 std::vector<glm::vec3> crosses; 222 std::vector<glm::vec3> crosses;

mercurial