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

Added AreaNthSelector #688

Merged
merged 8 commits into from
Mar 17, 2021
Merged

Added AreaNthSelector #688

merged 8 commits into from
Mar 17, 2021

Conversation

fedorkotov
Copy link
Contributor

Added AreaNthSelector that is useful for nested features selection. Especially to select one of coplanar nested wires for subsequent extrusion, cutting or filleting.

This selector was developed as a result of discussion in #684

Added AreaNthSelector that is useful for nested features selection. Especially to select one of coplanar nested wires for subsequent extrusion, cutting or filleting.
@fedorkotov
Copy link
Contributor Author

fedorkotov commented Mar 14, 2021

Unit tests for Solids and Shells are a bit contrived. Is there a way to get more than one Solid or Shell to select from while using Workplane? Or maybe using this selector for Solids and Shells makes no sense and support for them should be removed?

@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #688 (93fceff) into master (a54de64) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #688      +/-   ##
==========================================
+ Coverage   94.33%   94.41%   +0.08%     
==========================================
  Files          31       31              
  Lines        6810     6909      +99     
  Branches      732      740       +8     
==========================================
+ Hits         6424     6523      +99     
  Misses        252      252              
  Partials      134      134              
Impacted Files Coverage Δ
cadquery/selectors.py 98.14% <100.00%> (+0.12%) ⬆️
tests/__init__.py 88.23% <100.00%> (ø)
tests/test_selectors.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a54de64...93fceff. Read the comment docs.

@marcus7070 marcus7070 self-requested a review March 14, 2021 19:43
@fedorkotov
Copy link
Contributor Author

Black is complaining about formatting. IMHO it makes the code less readable by merging long sequences of fluent API calls that I format as one call per line into long lines with too many calls. But if that is the accepted formatting style of the project I will implement black's recommendations

@adam-urbanczyk adam-urbanczyk self-requested a review March 14, 2021 20:55
@marcus7070
Copy link
Member

Black is complaining about formatting. IMHO it makes the code less readable by merging long sequences of fluent API calls that I format as one call per line into long lines with too many calls. But if that is the accepted formatting style of the project I will implement black's recommendations

Yes please @fedorkotov. I know black isn't perfect, but it's much easier to read one consistent style.

@fedorkotov
Copy link
Contributor Author

fedorkotov commented Mar 15, 2021

Two questions

  1. AreaNthSelector is very similar to LengthNthSelector proposed in Length selector #646. Maybe I should add length selector in this pull request?
  2. Maybe I should add A (area) and L (length) to string selectors grammar with allowed usage like this
    1. >A - objects with the largest area
    2. <L[-2] - objects with second smallest length

Or is it better to keep things separated and both of these additional features should have their separate pull requests?

@marcus7070
Copy link
Member

  1. AreaNthSelector is very similar to LengthNthSelector proposed in Length selector #646.

I was thinking the same thing so I actually did #646 earlier today, thinking that the process would help me review this PR. I just put up the code as #690.

  1. Maybe I should add A (area) and L (length) to string selectors grammar with allowed usage like this

    1. >A - objects with the largest area
    2. <L[-2] - objects with second smallest length

Or is it better to keep things separated and both of these additional features should have their separate pull requests?

In this case I think we should do another PR, because we can roll area, length and radius selectors into one review.

@fedorkotov
Copy link
Contributor Author

I was thinking the same thing so I actually did #646 earlier today, thinking that the process would help me review this PR. I just put up the code as #690.

Ok. I will include LengthNthSelector into my pull request.
But first one more question. I see in your LengthNthSelector you use isinstance(obj, (...)) to determine what kind of Shape was passed into _NthSelector.key(..) implementation. I used Shape.ShapeType() in my AreaNthSelector for the same purpose. I assumed that comparing strings would be faster than type information manipulation but did not measure that. Should I change to isinstance? Or are these variants roughly equivalent?

In this case I think we should do another PR, because we can roll area, length and radius selectors into one review.

Ok.

Copy link
Member

@marcus7070 marcus7070 left a comment

Choose a reason for hiding this comment

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

You can include the LengthNthSelector code from #690 in here if you want, or we can work on #690 after this gets merged (which would be less work for you), I don't mind.

cadquery/selectors.py Outdated Show resolved Hide resolved
Comment on lines +6 to +7
.rect(20, 20)
.extrude(10) # solid 20x20x10 box
Copy link
Member

Choose a reason for hiding this comment

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

Usually I would insist these lines be changed to .box(20, 20, 10, centered=(True, True, False)) but this hangs the kernel in the final cutBlind step, and I can't work around it either! So it will have to stay as this rect version until that bug is fixed. No change required here, this is just a comment.

@marcus7070
Copy link
Member

marcus7070 commented Mar 15, 2021

Unit tests for Solids and Shells are a bit contrived. Is there a way to get more than one Solid or Shell to select from while using Workplane?

Something like

shell = (
    cq.Workplane()
    .box(1, 1, 1)
    .faces(">Z")
    .shell(0.1)
    .val()
)
workplane_shells = (
    cq.Workplane()
    .rarray(2, 2, 3, 4)
    .eachpoint(lambda loc: shell.located(loc))
)

edit: the above code produces a Workplane with 12 solids, not shells, which was a confusing example for me to choose, sorry.

You can also union different sized shells/solids, which would give you more variety to test an area selector on.

Or maybe using this selector for Solids and Shells makes no sense and support for them should be removed?

Solids and shells have clearly defined areas, so I support this selector working on them.

cadquery/selectors.py Outdated Show resolved Hide resolved
@marcus7070
Copy link
Member

If you check https://raw.githubusercontent.com/CadQuery/cadquery/master/doc/classreference.rst you'll see where we need to add AreaNthSelector to make it appear in the list of selectors at https://cadquery--688.org.readthedocs.build/en/688/classreference.html#selector-classes

- Switched Shape.ShapeType() to isinstance to determine what kind of Shape was passed into _NthSelector.key(..) implementation in AreaNthSelector for consistency with other selectors based on _NthSelector
- Added LengthNthSelector developed by @marcus7070 in CadQuery#690 with somewhat modified unit tests
- Added new selector references to documentation
- Black compatible code examples in AreaNthSelector docstring
- Explicitly marked _NthSelector class and _NthSelector.key(..) method as abstract using standard abc package
@fedorkotov
Copy link
Contributor Author

  • Switched Shape.ShapeType() to isinstance to determine what kind of Shape was passed into _NthSelector.key(..) implementation in AreaNthSelector for consistency with other selectors based on _NthSelector
  • Added LengthNthSelector developed by @marcus7070 in Length selector #690 with somewhat modified unit tests
  • Added new selector references to documentation
  • Black compatible code examples in AreaNthSelector docstring
  • Explicitly marked _NthSelector class and _NthSelector.key(..) method as abstract using standard abc package

Can't figure out what caused Windows pipelines to fail. Don't have access to Windows machine right now.

The log says

DLL load failed: The specified module could not be found

But which module and which dll? And why?
Have you experienced something like that before?

Copy link
Member

@marcus7070 marcus7070 left a comment

Choose a reason for hiding this comment

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

I think all our Windows CI are failing, it's not due to your code. Once we get that fixed and can see all the tests pass I think this looks good to merge.

Thanks for doing this @fedorkotov, there is a lot of work here especially the tests.

AreaNthSelector.key raises ValueError if temporary face creation fails for a wire for any reason (non-planar, non-closed). That causes _NthSelector that it inherits to ignore such wires. Done so for consistency with RadiusNthSelector that ignores anything it can not get radius from.
@fedorkotov
Copy link
Contributor Author

Forgot to check for non-planar or non-closed wires. Fixed.
For that I catch all exceptions that Face.makeFromWires(..) might throw. In general catching everything is a code smell. Should I catch something more specific?

@adam-urbanczyk
Copy link
Member

adam-urbanczyk commented Mar 16, 2021

@fedorkotov I propose to leave the catch as-is for now. makeFromWires needs some refactoring anyhow.

Thanks for all the hard work!

Copy link
Member

@marcus7070 marcus7070 left a comment

Choose a reason for hiding this comment

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

Good catch with that non-planar wire test.

@marcus7070 marcus7070 merged commit d5ce132 into CadQuery:master Mar 17, 2021
@marcus7070
Copy link
Member

Thanks @fedorkotov!

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.

3 participants