Currently, I am implementing triangulation using the Poly2Tri library.
This is my code:
var swctx = new poly2tri.SweepContext(contour);
swctx.triangulate();
var triangles = swctx.getTriangles();
for (var w = 0; w < triangles.length; w++) {
pts_tri = triangles[w].points_;
index1 = pts2.findIndex(x => x[0] == pts_tri[0].x && x[1] == pts_tri[0].y)
}
for (var k = 0; k < result.length; k++) {
geometry.faces.push(
new THREE.Face3(result[k][0].id, result[k][1].id, result[k][2].id)
);
}
No errors are encountered when loading the libraries!
Outcome:
1.) Mozilla Firefox: successfully operational without any error!
2.) Google Chrome: encountering issues with collinear points leading to failure.
I am wondering:
1.) Why does the same code and library work seamlessly on Firefox but faces difficulties on Chrome? Could it be due to the different JavaScript engines used by each browser?
Although Chrome utilizes the V8 engine and Firefox relies on Rhino/SpiderMonkey, doesn't this issue solely depend on the library for triangulation?
2.) Is there a way to make the code functional in Chrome while still utilizing the same library? How can this error be prevented?
3.) Does the library have built-in support for handling collinear points, considering that it functions flawlessly on Firefox?