23#ifndef VCL_ALGORITHMS_CORE_POLYGON_EAR_CUT_H
24#define VCL_ALGORITHMS_CORE_POLYGON_EAR_CUT_H
26#include "projection.h"
28#include <vclib/concepts/mesh.h>
29#include <vclib/space/core/polygon.h>
30#include <vclib/views/mesh.h>
32#if __has_include(<mapbox/earcut.hpp>)
33#include <mapbox/earcut.hpp>
37#include "../../../../../external/earcut.hpp-2.2.3/include/mapbox/earcut.hpp"
42namespace mapbox::util {
44template<
typename Scalar>
45struct nth<0, vcl::
Point2<Scalar>>
50template<
typename Scalar>
51struct nth<1, vcl::
Point2<Scalar>>
91template<Po
int2IteratorConcept Iterator>
92std::vector<uint>
earCut(Iterator begin, Iterator end)
94 using PointT = Iterator::value_type;
95 using Scalar = PointT::ScalarType;
102 std::vector<std::vector<Point2<Scalar>>>
poly;
103 poly.emplace_back(begin, end);
107 return mapbox::earcut<uint>(
poly);
145template<Po
int3IteratorConcept Iterator>
146std::vector<uint>
earCut(Iterator begin, Iterator end)
149 auto poly2D =
project(begin, end);
153 return earCut(poly2D.begin(), poly2D.end());
192template<FaceConcept Face>
195 using CoordType = Face::VertexType::CoordType;
196 return earCut(polygon.vertices() | views::coords);
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:49
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
auto project(Iterator begin, Iterator end)
Project a 3D polygon onto a plane, and return the 2D polygon.
Definition projection.h:42
std::vector< uint > earCut(Iterator begin, Iterator end)
Triangulates a simple polygon with no holes using the ear-cutting algorithm.
Definition ear_cut.h:92
Point< Scalar, 2 > Point2
A convenience alias for a 2-dimensional Point.
Definition point.h:720