215 [&crosses](const glm::vec3& vector) |
215 [&crosses](const glm::vec3& vector) |
216 { |
216 { |
217 return glm::dot(crosses[0], vector) < 1e-6; |
217 return glm::dot(crosses[0], vector) < 1e-6; |
218 }); |
218 }); |
219 } |
219 } |
|
220 |
|
221 /** |
|
222 * @brief Determines the winding of a 2d polygon |
|
223 * @param polygon |
|
224 * @return winding |
|
225 */ |
|
226 Winding geom::winding(const QPolygonF &polygon) |
|
227 { |
|
228 // based on https://stackoverflow.com/a/1165943 |
|
229 double sum = 0.0; |
|
230 for (int i = 0; i < polygon.size(); i += 1) |
|
231 { |
|
232 const QPointF& p1 = polygon[i]; |
|
233 const QPointF& p2 = polygon[(i + 1) % polygon.size()]; |
|
234 sum += (p2.x() - p1.x()) * (p2.y() + p1.y()); |
|
235 } |
|
236 return (sum < 0) ? Winding::Anticlockwise : Winding::Clockwise; |
|
237 } |