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

Rhino brep trimmed #1313

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed

* Changed and update the `compas_view2` examples into `compas_viewer`.
* Changed and updated the `compas_view2` examples into `compas_viewer`.
* Changed `compas.scene.Scene` to inherent from `compas.datastructrues.Tree`.
* Changed `compas.scene.SceneObject` to inherent from `compas.datastructrues.TreeNode`.
* `RhinoBrep.trimmed` returns single result or raises `BrepTrimmingError` instead of returning a list.

### Removed

Expand Down
52 changes: 37 additions & 15 deletions src/compas_rhino/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,30 @@ def trim(self, plane, tolerance=TOLERANCE):
----------
plane : :class:`compas.geometry.Frame` or :class:`compas.geometry.Plane`
The frame or plane to use when trimming. The discarded bit is in the direction of the frame's normal.

tolerance : float
The precision to use for the trimming operation.

Notes
-----
Trimming operation may result in multiple results (breps). When trimming, only one is used.
The used bit is the one on the opposite side of the cutting plane's normal.

Returns
-------
None

"""
results = self.trimmed(plane, tolerance)
if not results:
raise BrepTrimmingError("Trim operation ended with no result")
Raises
------
BrepTrimmingError
If the trimming operation ended with no result.

self._brep = results[0].native_brep
See Also
--------
:meth:`compas_rhino.geometry.RhinoBrep.trimmed`

"""
result = self.trimmed(plane, tolerance)
self._brep = result.native_brep

def trimmed(self, plane, tolerance=TOLERANCE):
"""Returns a trimmed copy of this brep by the given trimming plane.
Expand All @@ -394,26 +404,38 @@ def trimmed(self, plane, tolerance=TOLERANCE):
----------
plane : :class:`compas.geometry.Frame` or :class:`compas.geometry.Plane`
The frame or plane to use when trimming. The discarded bit is in the direction of the plane's normal.

tolerance : float
The precision to use for the trimming operation.

Notes
-----
Trimming operation may result in multiple results (breps). When trimming, only one is used.
The used bit is the one on the opposite side of the cutting plane's normal.

Returns
-------
:class:`~compas_rhino.geometry.RhinoBrep`

Raises
------
BrepTrimmingError
If the trimming operation ended with no result.

See Also
--------
:meth:`compas_rhino.geometry.RhinoBrep.trim`

"""
if isinstance(plane, Frame):
plane = Plane.from_frame(plane)
results = self._brep.Trim(plane_to_rhino(plane), tolerance)

breps = []
for result in results:
capped = result.CapPlanarHoles(TOLERANCE)
if capped:
result = capped
breps.append(RhinoBrep.from_native(result))
return breps
if not results:
raise BrepTrimmingError("Trim operation ended with no result")
result = results[0]
capped = result.CapPlanarHoles(TOLERANCE)
Copy link
Member

Choose a reason for hiding this comment

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

in the signature, tolerance=None. then tolerance = tolerance or TOL.absolute, with at the top (if it is not already there) from compas.tolerance import TOL

Copy link
Member

Choose a reason for hiding this comment

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

and then, finally, capped = result.CapPlanarHoles(tolerance)

Copy link
Member Author

Choose a reason for hiding this comment

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

@tomvanmele done.
Just curious why not tolerance=TOL.absolute in signature? as it returns a float (immutable)

Copy link
Member

Choose a reason for hiding this comment

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

that would have also been an option indeed. as long as it is not a hard coded tolerance value...

if capped:
result = capped
return RhinoBrep.from_native(result)

@classmethod
def from_boolean_difference(cls, breps_a, breps_b):
Expand Down
Loading