@@ -63,7 +63,7 @@ std::vector<Point> jsArrayToPointVector(const emscripten::val& jsArray) {
6363 unsigned length = jsArray[" length" ].as <unsigned >();
6464 vertices.reserve (length);
6565
66- for (unsigned i = 0 ; i < length; i++ ) {
66+ for (int i = static_cast < int >(length) - 1 ; i >= 0 ; --i ) {
6767 emscripten::val jsPoint = jsArray[i];
6868 // Use property access instead of method calls for better compatibility
6969 long x = jsPoint[" x" ].as <long >();
@@ -211,35 +211,7 @@ EMSCRIPTEN_BINDINGS(libnest2d_js) {
211211 std::vector<Point> vertices = jsArrayToPointVector (jsVertices);
212212 PolygonImpl polygon;
213213 polygon.Contour = vertices;
214-
215- // Check if we need to reverse the orientation
216- // For libnest2d with Clipper, we want the area to be positive
217- double area = sl::area (polygon);
218- std::cerr << " [DEBUG] Initial polygon area: " << area << std::endl;
219-
220- if (area < 0 ) {
221- std::cerr << " [DEBUG] Area is negative, reversing vertex order" << std::endl;
222- std::reverse (vertices.begin (), vertices.end ());
223- polygon.Contour = vertices;
224-
225- // Verify the area is now positive
226- double newArea = sl::area (polygon);
227- std::cerr << " [DEBUG] Area after reversal: " << newArea << std::endl;
228-
229- for (size_t i = 0 ; i < vertices.size (); ++i) {
230- std::cerr << " [DEBUG] Fixed Vertex " << i << " : (" << getX (vertices[i]) << " , " << getY (vertices[i]) << " )" << std::endl;
231- }
232- } else {
233- std::cerr << " [DEBUG] Area is already positive, no reversal needed" << std::endl;
234- }
235-
236- Item item (polygon);
237-
238- std::cerr << " [DEBUG] Created item - area: " << item.area ()
239- << " , vertexCount: " << item.vertexCount ()
240- << " , binId: " << item.binId () << std::endl;
241-
242- return item;
214+ return Item (polygon);
243215 }))
244216 .function (" binId" , select_overload<int () const >(&Item::binId))
245217 .function (" setBinId" , select_overload<void (int )>(&Item::binId))
0 commit comments