cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Free function api

Open adam-urbanczyk opened this issue 1 year ago • 5 comments

A free function API for cq.Shape. Originally inspired by #1269.

The idea is to provide a low-level but reasonably user friendly API for cq.Shape

  • [x] primitives
  • [x] operations
  • [x] bool op as operators
  • [x] moved with multiple locations
    • [ ] Overload for *locs
  • [ ] Location constructor improvements ?
  • [x] additional factories ?
  • [ ] tests
  • [ ] docs

adam-urbanczyk avatar Dec 20 '23 09:12 adam-urbanczyk

Codecov Report

Attention: Patch coverage is 99.23664% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 95.04%. Comparing base (99792e5) to head (066795c). Report is 2 commits behind head on master.

Files Patch % Lines
cadquery/occ_impl/shapes.py 99.18% 3 Missing and 2 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1469      +/-   ##
==========================================
+ Coverage   94.54%   95.04%   +0.49%     
==========================================
  Files          28       28              
  Lines        5848     7202    +1354     
  Branches     1166     1572     +406     
==========================================
+ Hits         5529     6845    +1316     
- Misses        193      224      +31     
- Partials      126      133       +7     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 20 '23 20:12 codecov[bot]

@lorenzncode will you have bandwidth/interest to look at this?

adam-urbanczyk avatar Jan 30 '24 18:01 adam-urbanczyk

@adam-urbanczyk Yes, at first glance this looks very interesting. I'll find some time to take a look.

lorenzncode avatar Jan 31 '24 01:01 lorenzncode

I started experimenting. It seems very easy to use! Can revolve be changed to accept Shell?

    # https://groups.google.com/g/cadquery/c/B-9w-U3gs1M/m/YhwbkMYPCAAJ
    from cadquery.occ_impl.shapes import spline, loft, revolve

    pts0 = [(1, 1, 0), (1, 1, 1), (1.2, 0.7483, 2)]
    pts1 = [(2, 2, 0), (2, 2, 1), (2.2, 1.7776, 2)]
    edge0 = spline(pts0)
    edge1 = spline(pts1)

    sh0 = loft([edge0, edge1])
    result = revolve(sh0, pts0[0], pts1[0], 180) # changed revolve _get Shell

test_free_api_jupyter.zip

lorenzncode avatar Feb 09 '24 05:02 lorenzncode

I added shape normalization. For your example loft returns Face instead of Shell.

adam-urbanczyk avatar Feb 09 '24 18:02 adam-urbanczyk

I think it is ready for a fist pass. Take a look at the new doc section to get a glimpse.

adam-urbanczyk avatar Apr 22 '24 19:04 adam-urbanczyk

Very exciting new CQ development! I checked out the branch and started trying it out. Will play around with it more.

lorenzncode avatar Apr 25 '24 02:04 lorenzncode

Thanks for all the work on this @adam-urbanczyk ! The examples run fine for me, and the code looks good.

Either in this PR or a separate PR, we will also need to update setup.py for the new multimethod version declaration. With version 1.9.1 I get an intermittent error. This means we will probably see some support issues after the next release where people did not upgrade their multimethod version or create a fresh environment.

jmwright avatar Apr 29 '24 15:04 jmwright

OK, I think I resolved all the points. Let me know if you are OK with merging.

adam-urbanczyk avatar May 04 '24 13:05 adam-urbanczyk

Thank you for the new API!

lorenzncode avatar May 05 '24 00:05 lorenzncode

+1 to merge

jmwright avatar May 05 '24 00:05 jmwright