| 221 | } |
| 222 | |
| 223 | std::vector<Polygon> Polygon::triangulate(const TriangulationMethods& method) const |
| 224 | { |
| 225 | // TODO Add more triangulation methods. |
| 226 | // https://en.wikipedia.org/wiki/Polygon_triangulation |
| 227 | std::vector<Polygon> polygons; |
| 228 | if (vertices_.size() < 3) |
| 229 | return polygons; |
| 230 | |
| 231 | size_t nPolygons = vertices_.size() - 2; |
| 232 | polygons.reserve(nPolygons); |
| 233 | |
| 234 | if (nPolygons < 1) { |
| 235 | // Special case. |
| 236 | polygons.push_back(*this); |
| 237 | } else { |
| 238 | // General case. |
| 239 | for (size_t i = 0; i < nPolygons; ++i) { |
| 240 | Polygon polygon({vertices_[0], vertices_[i + 1], vertices_[i + 2]}); |
| 241 | polygons.push_back((polygon)); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return polygons; |
| 246 | } |
| 247 | |
| 248 | Polygon Polygon::fromCircle(const Position center, const double radius, |
| 249 | const int nVertices) |
no outgoing calls