jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.58k stars 505 forks source link

fix(modeling): added orientation option to polygon #1315

Closed z3dev closed 5 months ago

z3dev commented 6 months ago

These changes add a new option to the polygon primitive; orientation. If set to 'clockwise' then the geometry is reversed.

These changes address #1012

All Submissions:

z3dev commented 5 months ago

Looks good, and I confirmed the behavior with a test file.

Here's a suggested test to add to polygon.test.js which fails on master but passes on this branch:

test('polygon: clockwise points', (t) => {
  const poly = polygon({
    points: [[-10, -0], [-10, -10], [-15, -5]],
    orientation: "clockwise",
  })
  t.is(poly.sides.length, 3)
  t.is(measureArea(poly), 25)
})

@platypii thanks. i added the test case. should be ready to merge now.