Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'cut' introduced in complex polygon #100

Closed
jucon-bv opened this issue Jul 24, 2022 · 1 comment
Closed

'cut' introduced in complex polygon #100

jucon-bv opened this issue Jul 24, 2022 · 1 comment

Comments

@jucon-bv
Copy link

To reproduce please check this code:

// The number type to use for tessellation
using Coord = double;

// The index type. Defaults to uint32_t, but you can also pass uint16_t if you know that your
// data won't have more than 65536 vertices.
using N = uint32_t;

// Create array
using Point = std::array<Coord, 2>;
std::vector<std::vector<Point>> polygon;

// Fill polygon structure with actual data. Any winding order works.
// The first polyline defines the main polygon.
polygon.push_back({{-1.095, -1.025}, {1.095, -1.025},{1.095, 1.025},{-1.095, 1.025}});
// Following polylines define holes.
polygon.push_back({{0.425, -0.965},{0.425, 0.965},{1.035, 0.965},{1.035, -0.965}});
polygon.push_back({{-1.035, -0.965},{-1.035, 0.965},{0.365, 0.965},{0.365, -0.965}});

// Run tessellation
// Returns array of indices that refer to the vertices of the input polygon.
// e.g: the index 6 would refer to {25, 75} in this example.
// Three subsequent indices form a triangle. Output triangles are clockwise.
std::vector<N> indices = mapbox::earcut<N>(polygon);

it's a rectangle with two rectangular holes, leaving only a small space in between those holes. It appears earcut 'cuts' this space ( see screenshot ). Is this expected behavior or can this be fixed?

Screenshot from 2022-07-24 11-48-52

@mrgreywater
Copy link
Collaborator

This is valid behaviour for this library. It's been created mostly to create triangles for graphics rendering, less so for strictly valid triangulation for e.g. navmeshing. Libtess might give you more accurate results (with a performance penalty).

@mourner mourner closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants