Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for V3 API #1249

Open
hjfreyer opened this issue May 17, 2023 · 2 comments
Open

Suggestion for V3 API #1249

hjfreyer opened this issue May 17, 2023 · 2 comments
Labels

Comments

@hjfreyer
Copy link
Contributor

I happened to see this wiki page and I thought I'd offer my unsolicited opinion: https://github.com/jscad/OpenJSCAD.org/wiki/JSCAD-V3

I really like jscad, but I often find the APIs surprising, particularly with respect to how operations affect groups of geometries I pass to them.

For instance, I'm modeling a table right now, and I have an array of two legs and a plate that they'll connect to. I just ran this:

[legs, plate] = align({modes: ['none', 'center', 'none'], grouped: true}, [legs, plate]);

However, this didn't work. With console.log, I saw that the align operation had converted my argument with structure [[leg1, leg2], plate] into a flat array: [leg1, leg2, plate]. I run into this kind of confusion all the time.

My advice would be to consistently treat arrays of geometries as single objects, or perhaps introduce a first-class "group" type. For instance, centerX([a, b, c]) shouldn't center each object individually. If I wanted that behavior, I'd write [a, b, c].map(x => centerX(x)). Some operations may still want to recurse over the structure (e.g. intersect([a, [b, c]], d) should go in and intersect d with each item in the first argument), but it shouldn't disrupt the structure I provided.

Thanks for the great library! Hope this helps.

@z3dev
Copy link
Member

z3dev commented Jun 23, 2023

@hjfreyer nice suggestions. thanks.

The suggestion to 'align' based on the structure of the array seems reasonable, but probably requires another 'option'. Feel free to submit some API changes. We are working on V3 now, and have already broken a few of the APIs.

The reason for the flattening of objects is to treat the parameters in a consistent manner. For example...

let results = align({}, circle())
results = align({}, circle(), square())
results = align({}, ...contents)
results = align({}, [a, b, c])

Yeah. It probably doesn't make sense for lots of people, nor all the time, but at least it's consistent throughout the functions of JSCAD. No surprises. All input is flattened.

@z3dev
Copy link
Member

z3dev commented Jan 28, 2024

@hjfreyer V3 recently had a major change to the APIs in general.

I think that @platypii could add a few comments on the changes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants