jscad / csg.js

DEPRECATED: CSG Library for JSCAD (See the link below)
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling
MIT License
217 stars 56 forks source link

Reorganization of Primitives #169

Closed z3dev closed 5 years ago

z3dev commented 5 years ago

This pull request adds the 2D and 3D primitives as a separate module. The goals are:

Major Changes:

Primitives:

arc

circle (alias of ellipse, see ellipse.js)

cube (alias of cuboid, see cuboid.js)

cuboid

cylinder (alias of cylinderElliptic, see cylinderElliptic.js)

cylinderElliptic

ellipse

ellipsoid

geodesicSphere

line

polygon

polyhedron

rectangle

roundedCuboid

roundedCylinder.js

roundedRectangle

sphere (alias of ellipsoid, see ellipsoid.js)

square (alias of rectangle, see rectangle.js)

star

torus

z3dev commented 5 years ago

It's time for another long discussion. I added notes to those primitives with issues.

It's my feeliing that primitives should be just that, and not rely upon other operations to produce geometry. For example 'torus' seems like a primitive but relies upon 'extrudeRotate'. This is a special compound shape, and may be better packaged as part of 'extrusions'.

z3dev commented 5 years ago

@kaosat-dev You will like this... it seems that the logic inside sphere() was actually for ellipsoid(), but had the X, Y, Z radius set to the same value. I changed things, exposing ellipsoid as a primitive.

https://en.wikipedia.org/wiki/Ellipsoid

kaosat-dev commented 5 years ago

very cool @z3dev ! I am currently reviewing, thanks for the awesome work, will post back in a bit

z3dev commented 5 years ago

@kaosat-dev What to do with polygon? The API is still very SCAD-like, and very confusing. I'm not sure why the complex logic for lists-of-lists was required.

kaosat-dev commented 5 years ago

@z3dev can you please explain a bit more about what you mean by list of lists ?

kaosat-dev commented 5 years ago

@kaosat-dev You will like this... it seems that the logic inside sphere() was actually for ellipsoid(), but had the X, Y, Z radius set to the same value. I changed things, exposing ellipsoid as a primitive.

https://en.wikipedia.org/wiki/Ellipsoid

Haha that is good indeed !

z3dev commented 5 years ago

@z3dev can you please explain a bit more about what you mean by list of lists ?

polygon() needs some help...

i think this is unsupportable as written. there are many issues with rotation, hole detection, etc.

z3dev commented 5 years ago

polgyon()

it should follow polyhedron, and ONLY use named options; 'points' and 'paths' DONE

z3dev commented 5 years ago

roundedCube() needs to be rewritten as well. There are precision errors if the resolution is adjusted to a sphere that is not planiar with X,Y,Z. For example.

let obj = CSG.roundedCube({radius: [5,10,15], roundradius: 3, resolution: 6});

kaosat-dev commented 5 years ago

@z3dev good job on the naming of polyhedron: for now I would keep it 'as it is ' for the rest and revisit later : that function is used A LOT for all stl & other format imports, so breaking things even further can wait ? what do you think ?

about roundedCube: ah yes, lots of pitfalls ! (I even recall that we had notes about that one ?) also just thought about something : I think it should be roundingSegments or roundSegments for the rounding 'resolution' to make it clearer About the precison errors, set of incompatible parameters: can they be caught and an error be thrown or are there realistically too many issues ?

z3dev commented 5 years ago

polygon() : so breaking things even further can wait ? what do you think ?

Sounds like a good suggestion. Let's run with the latest. There could be a few more changes coming.

z3dev commented 5 years ago

WOW. That was one major pull request!

I'm fine with merging now.

@kaosat-dev This is now done, unless you want further changes.

kaosat-dev commented 5 years ago

This was epic, thanks a ton @z3dev ! WELL DONE ! merging :)