Skip to content

Commit

Permalink
Merge branch 'main' into use-tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Apr 24, 2024
2 parents 8b5c4cc + 6ce0be1 commit 599f063
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ insert_final_newline = true
indent_style = space
indent_size = 4
charset = utf-8
max_line_length = 120
max_line_length = 179

[*.{bat,cmd,ps1}]
end_of_line = crlf
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 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`.
Expand All @@ -25,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed bug in `Mesh.thickened`.
* Fixed various bugs in `compas.geometry.Quaternion`.
* Changed repo config to `pyproject.toml`.
* Changed `RhinoBrep.trimmed` to return single result or raise `BrepTrimmingError` instead of returning a list.
* Changed order of imports according to `isort` and changed line length to `179`.
* Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`.
* Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`.
Expand Down
3 changes: 1 addition & 2 deletions docs/devguide/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ Naming conventions
Line length
-----------

**COMPAS uses a line length of 120 characters**. While longer than the 80 characters recommended by ``PEP8``, it is in our opinion a more reasonable limit for modern displays.
This is enforced and can be automatically set using ``black -l 120``.
**COMPAS uses a line length of 180 characters**. While longer than the 80 characters recommended by ``PEP8``, it is in our opinion a more reasonable limit for modern displays.

**Indentations are 4 spaces**. Tab to spaces setting can be set in ``.editorconfig`` which is respected by most editors. For more information see `EditorConfig <https://editorconfig.org/>`_.

Expand Down
2 changes: 1 addition & 1 deletion docs/devguide/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To set up a developer environment
.. code-block:: bash
cd path/to/compas
pip install -r requirements-dev.txt
pip install -e ".[dev]"
4. Make sure all tests pass and the code is free of lint:

Expand Down
75 changes: 48 additions & 27 deletions src/compas_rhino/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
from .loop import RhinoBrepLoop
from .vertex import RhinoBrepVertex

TOLERANCE = 1e-6


class RhinoBrep(Brep):
"""Rhino Brep backend class.
Expand Down Expand Up @@ -241,7 +239,7 @@ def from_extrusion(cls, curve, vector, cap_ends=True):
raise BrepError("Failed to create extrusion from curve: {} and vector: {}".format(curve, vector))
rhino_brep = extrusion.ToBrep()
if cap_ends:
capped = rhino_brep.CapPlanarHoles(TOLERANCE)
capped = rhino_brep.CapPlanarHoles(TOL.absolute)
if capped:
rhino_brep = capped
return cls.from_native(rhino_brep)
Expand Down Expand Up @@ -326,7 +324,7 @@ def contains(self, object):
raise BrepError("Cannot check for containment if brep is not manifold or is not closed")

if isinstance(object, Point):
return self._brep.IsPointInside(point_to_rhino(object), TOLERANCE, False)
return self._brep.IsPointInside(point_to_rhino(object), TOL.absolute, False)
else:
raise NotImplementedError

Expand Down Expand Up @@ -364,55 +362,78 @@ def transform(self, matrix):
"""
self._brep.Transform(transformation_to_rhino(matrix))

def trim(self, plane, tolerance=TOLERANCE):
def trim(self, plane, tolerance=None):
"""Trim this brep by the given trimming plane.
Parameters
----------
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, optional
The precision to use for the trimming operation. Defaults to `TOL.absolute`.
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):
def trimmed(self, plane, tolerance=None):
"""Returns a trimmed copy of this brep by the given trimming plane.
Parameters
----------
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, optional
The precision to use for the trimming operation. Defaults to `TOL.absolute`.
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`
"""
tolerance = tolerance or TOL.absolute
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)
if capped:
result = capped
return RhinoBrep.from_native(result)

@classmethod
def from_boolean_difference(cls, breps_a, breps_b):
Expand All @@ -438,7 +459,7 @@ def from_boolean_difference(cls, breps_a, breps_b):
resulting_breps = Rhino.Geometry.Brep.CreateBooleanDifference(
[b.native_brep for b in breps_a],
[b.native_brep for b in breps_b],
TOLERANCE,
TOL.absolute,
)
return [RhinoBrep.from_native(brep) for brep in resulting_breps]

Expand All @@ -464,7 +485,7 @@ def from_boolean_union(cls, breps_a, breps_b):
if not isinstance(breps_b, list):
breps_b = [breps_b]

resulting_breps = Rhino.Geometry.Brep.CreateBooleanUnion([b.native_brep for b in breps_a + breps_b], TOLERANCE)
resulting_breps = Rhino.Geometry.Brep.CreateBooleanUnion([b.native_brep for b in breps_a + breps_b], TOL.absolute)
return [RhinoBrep.from_native(brep) for brep in resulting_breps]

@classmethod
Expand All @@ -491,7 +512,7 @@ def from_boolean_intersection(cls, breps_a, breps_b):
resulting_breps = Rhino.Geometry.Brep.CreateBooleanIntersection(
[b.native_brep for b in breps_a],
[b.native_brep for b in breps_b],
TOLERANCE,
TOL.absolute,
)
return [RhinoBrep.from_native(brep) for brep in resulting_breps]

Expand Down Expand Up @@ -529,5 +550,5 @@ def split(self, cutter):
list of zero or more resulting Breps.
"""
resulting_breps = self._brep.Split(cutter.native_brep, TOLERANCE)
resulting_breps = self._brep.Split(cutter.native_brep, TOL.absolute)
return [RhinoBrep.from_native(brep) for brep in resulting_breps]

0 comments on commit 599f063

Please sign in to comment.