Repository: elalish/manifold (language: python)

Issue:
js bindings: CrossSection.toPolygons() return value doesn't match typescript type
The points are objects of type {x,y} instead of an array [x,y] like the types indicate.
example: run this on the web example `console.log(CrossSection.square().toPolygons());`
output:
```
[
    [
        {
            "x": 0,
            "y": 0
        },
        {
            "x": 1,
            "y": 0
        },
        {
            "x": 1,
            "y": 1
        },
        {
            "x": 0,
            "y": 1
        }
    ]
]
```

expected:
```
[
    [
        [0,0],
        [1,0],
        [1,1],
        [0,1]
    ]
]
```

I can look into fixing it later if no one wants to fix it.


Discussion / hints:
Thanks, good find. @pca006132 this makes me wonder if we should do any additional API changes here. We switched from `Mesh` vector-of-vec3 to `MeshGL` flat vectors. Should we do something similar with `Polygon`? 
Idk, what I am sure is we should double check binding APIs before we release v3.0 :P
sounds like you've got your work cut out for checking all the bindings. If I have time, I may be able to do an initial pass on all the cross section bindings if that helps. I do also see that theres been a lot of activity recently and things might change as you've mentioned
As part of #930 I started to write a bindings-specific test suite that could at least run some sanity checks. However, given the scope of the API surface, I didn't get very far. If I have time, I can revisit that change.

Fix patch:
diff --git a/bindings/wasm/bindings.js b/bindings/wasm/bindings.js
index dbea0692c..de757ae84 100644
--- a/bindings/wasm/bindings.js
+++ b/bindings/wasm/bindings.js
@@ -190,7 +190,7 @@ Module.setup = function() {
 
   Module.CrossSection.prototype.toPolygons = function() {
     const vec = this._ToPolygons();
-    const result = vec2polygons(vec);
+    const result = vec2polygons(vec, v => [v.x, v.y]);
     vec.delete();
     return result;
   };


Test patch:
diff --git a/bindings/wasm/examples/bindings.test.ts b/bindings/wasm/examples/bindings.test.ts
new file mode 100644
index 000000000..a4a011c07
--- /dev/null
+++ b/bindings/wasm/examples/bindings.test.ts
@@ -0,0 +1,22 @@
+import {beforeAll, expect, suite, test} from 'vitest';
+
+import Module, {type ManifoldToplevel} from './built/manifold'
+
+let manifoldModule: ManifoldToplevel;
+
+beforeAll(async () => {
+  manifoldModule = await Module();
+  manifoldModule.setup();
+});
+
+suite('CrossSection Bindings', () => {
+  test('ToPolygons return correct shape', () => {
+    const polygons = manifoldModule.CrossSection.square().toPolygons();
+    expect(polygons).toHaveLength(1);
+    expect(polygons[0]).toHaveLength(4);
+    expect(polygons[0]).toContainEqual([0, 0]);
+    expect(polygons[0]).toContainEqual([0, 1]);
+    expect(polygons[0]).toContainEqual([1, 0]);
+    expect(polygons[0]).toContainEqual([1, 1]);
+  });
+});
\ No newline at end of file