| 18 | } |
| 19 | |
| 20 | static bool is_ear(const size_t i, const std::vector<Vec3> &points, const std::vector<size_t> &indices, const Vec3 &normal) |
| 21 | { |
| 22 | const size_t prev = indices[(i + indices.size() - 1) % indices.size()]; |
| 23 | const size_t curr = indices[i]; |
| 24 | const size_t next = indices[(i + 1) % indices.size()]; |
| 25 | |
| 26 | const Vec3 &v1 = points[prev]; |
| 27 | const Vec3 &v2 = points[curr]; |
| 28 | const Vec3 &v3 = points[next]; |
| 29 | |
| 30 | // check if angle is convex |
| 31 | const Vec3 d1 = v2 - v1; |
| 32 | const Vec3 d2 = v3 - v2; |
| 33 | |
| 34 | if (Vec3::dot(Vec3::cross(d1, d2), normal) <= 0.0f) |
| 35 | { |
| 36 | return false; // not convex |
| 37 | } |
| 38 | |
| 39 | // check for no other points inside triangle |
| 40 | for (size_t j = 0; j < indices.size(); j++) |
| 41 | { |
| 42 | if (j == (i - 1 + indices.size()) % indices.size() || j == i || j == (i + 1) % indices.size()) |
| 43 | { |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | if (is_in_triangle(points[indices[j]], v1, v2, v3, normal)) |
| 48 | { |
| 49 | return false; // point inside triangle |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return true; // ear found |
| 54 | } |
| 55 | |
| 56 | // main functions |
| 57 |
no test coverage detected