mapbox / earcut.hpp

Fast, header-only polygon triangulation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Member function of Earcut Assumes that the point type has a size member function

gracicot opened this issue · comments

Namely, the functions Earcut<N>::operator() and Earcut<N>::linkedList are using points[i].size(), but it is documented that specializing the nth is enough to make it compatible.

I propose adding a constexpr static member function in nth that returns the size. By default it should return std::tuple_size<T>::value. Adding a new struct that has a ::value static data member is also an option.

Tell me which one you prefer and I'll create a pull request :)

I think there's some confusion about the types.

The input type for earcut has a structure like vector<vector<point>>. For the point type, it's sufficient if nth<0, ...> and nth<1, ...> is defined. For the vector type, it's necessary to define container methods such as 'size', operator[] etc.

Namely, the functions Earcut::operator() and Earcut::linkedList are using points[i].size(), but it is documented that specializing the nth is enough to make it compatible.

points[i] would be a vector, therefore points[i].size() is the number of points of the polygon/point-list/vector with the index i.

Hmm, right now I'm trying to send a std::vector<glm::vec2>. I would need to send a std::vector<std::vector<glm::vec2>>? What is the second dimension is supposed to represent? I'm not sure how to layout my data

Ah! I see, this is to support holes inside a polygon?

Yes, to support holes. The first vector<point> is the main surrounding polygon, further point-lists define holes.

std::vector<std::vector<glm::vec2>> would work.

Perfect! Sorry for the noise.

For the records, since I'm not supporting holes in my application, I opted to send std::span<std::vector<glm::vec2>, 1>{std::addressof(points), 1}, where points is a std::vector<glm::vec2>