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

Fix union with None #1560

Merged
merged 2 commits into from
Apr 17, 2024
Merged

Fix union with None #1560

merged 2 commits into from
Apr 17, 2024

Conversation

adam-urbanczyk
Copy link
Member

Closes #1536

Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.54%. Comparing base (3451007) to head (926212a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1560   +/-   ##
=======================================
  Coverage   94.54%   94.54%           
=======================================
  Files          28       28           
  Lines        5846     5848    +2     
  Branches     1165     1166    +1     
=======================================
+ Hits         5527     5529    +2     
  Misses        193      193           
  Partials      126      126           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@michaelgale
Copy link

Wow! Really grateful that this has finally been changed. I can't tell you how much boilerplate code I've written to handle the inevitable union to "None" scenario when making composite solids/geometries from iteration.

@adam-urbanczyk
Copy link
Member Author

Thanks @michaelgale ! Was there something stopping you from opening an issue or PR? Or did we miss it somehow?

@michaelgale
Copy link

Thanks @michaelgale ! Was there something stopping you from opening an issue or PR? Or did we miss it somehow?

I am somewhat hesitant to suggest changes to a mature core API since these types of changes can have unpredictable consequences for other users. Since this issue didn't represent a bug or unexpected behaviour, I didn't think to ever raise a PR or issue. Since CQ is so easily extended with plugins, I tend to rely on this mechanism to introduce syntactic shortcuts and convenience functions to streamline my integrations with CQ. In future, I might lower my threshold for raising issues and/or contributing changes with a PR. Thanks again to the CQ team for maintaining this project.

Copy link
Member

@lorenzncode lorenzncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey just one comment regarding boilerplate. This behavior results in additional parents which may be different than current boilerplate. As @michaelgale mentions iteration, I suppose it depends on size of the iteration or sparseness whether there is any significant noticeable impact.

import cadquery as cq

r0 = cq.Workplane().cylinder(1, 10)

for i in range(1, 101):
    if i == 50:
        obj = cq.Workplane().box(1, 1, 10)
    else:
        obj = None

    r0 = r0.union(obj)

image

@adam-urbanczyk
Copy link
Member Author

@lorenzncode I'm not sure that I understand. Currently union with None results in an error.

@jmwright
Copy link
Member

Looks good, thanks @adam-urbanczyk

@lorenzncode
Copy link
Member

@adam-urbanczyk Right, I'm only pointing out that skipping union to avoid the error is not exactly the same as this fix.

In #1536 , union2 is defined to avoid the error by skipping the call to union.

In the PR branch, calling union with None extends the Workplane chain and does not result in error.

The result at the end of the chain is the same in either case only that the length of the chain is different.

@adam-urbanczyk
Copy link
Member Author

@adam-urbanczyk Right, I'm only pointing out that skipping union to avoid the error is not exactly the same as this fix.

In #1536 , union2 is defined to avoid the error by skipping the call to union.

That is the intention, .union() will in general union items on the stack, so creating a new object is desired. Shall I merge?

@lorenzncode
Copy link
Member

That makes sense to me. +1 to merge. Thanks @adam-urbanczyk

@adam-urbanczyk adam-urbanczyk merged commit 99792e5 into master Apr 17, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workplane.union error with None
4 participants