Skip to content

Commit

Permalink
added vertex information to BrepTrim
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Nov 13, 2024
1 parent 46b2863 commit 649a844
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added attribute `start_vertex` to `compas.geometry.BrepTrim`.
* Added attribute `end_vertex` to `compas.geometry.BrepTrim`.
* Added attribute `vertices` to `compas.geometry.BrepTrim`.
* Added attribute `start_vertex` to `compas_rhino.geometry.RhinoBrepTrim`.
* Added attribute `start_vertex` to `compas_rhino.geometry.RhinoBrepTrim`.
* Added attribute `vertices` to `compas_rhino.geometry.RhinoBrepTrim`.

### Changed

### Removed
Expand Down
17 changes: 17 additions & 0 deletions src/compas/geometry/brep/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class BrepTrim(Data):
True if this trim is reversed from its associated edge curve and False otherwise.
native_trim : Any
The underlying trim object. Type is backend-dependent.
start_vertex : Any, read-only
The start vertex of this trim.
end_vertex : Any, read-only
The end vertex of this trim.
vertices : list[Any], read-only
"""

Expand All @@ -44,3 +49,15 @@ def is_reversed(self):
@property
def native_trim(self):
raise NotImplementedError

@property
def start_vertex(self):
raise NotImplementedError

@property
def end_vertex(self):
raise NotImplementedError

@property
def vertices(self):
raise NotImplementedError
31 changes: 28 additions & 3 deletions src/compas_rhino/geometry/brep/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from compas.geometry import BrepTrim
from compas_rhino.geometry import RhinoNurbsCurve

from .vertex import RhinoBrepVertex


class RhinoBrepTrim(BrepTrim):
"""An interface for a Brep Trim
"""Trims hold topological information about how the edges of a Brep face are are organized.
Attributes
----------
Expand All @@ -21,6 +23,12 @@ class RhinoBrepTrim(BrepTrim):
True if this trim is reversed from its associated edge curve and False otherwise.
native_trim : :class:`Rhino.Geometry.BrepTrim`
The underlying Rhino BrepTrim object.
start_vertex : :class:`compas_rhino.geometry.RhinoBrepVertex`, read-only
The start vertex of this trim.
end_vertex : :class:`compas_rhino.geometry.RhinoBrepVertex`, read-only
The end vertex of this trim.
vertices : list[:class:`compas_rhino.geometry.RhinoBrepVertex`], read-only
The list of vertices which comprise this trim (start and end).
"""

Expand All @@ -30,6 +38,8 @@ def __init__(self, rhino_trim=None):
self._curve = None
self._is_reversed = None
self._iso_type = None
self._start_vertex = None
self._end_vertex = None
if rhino_trim:
self.native_trim = rhino_trim

Expand All @@ -40,7 +50,8 @@ def __init__(self, rhino_trim=None):
@property
def __data__(self):
return {
"vertex": self._trim.StartVertex.VertexIndex,
"start_vertex": self._trim.StartVertex.VertexIndex,
"end_vertex": self._trim.EndVertex.VertexIndex,
"edge": self._trim.Edge.EdgeIndex if self._trim.Edge else -1, # singular trims have no associated edge
"curve": RhinoNurbsCurve.from_rhino(self._trim.TrimCurve.ToNurbsCurve()).__data__,
"iso": str(self._trim.IsoStatus),
Expand Down Expand Up @@ -68,7 +79,7 @@ def __from_data__(cls, data, builder):
curve = RhinoNurbsCurve.__from_data__(data["curve"]).rhino_curve
iso_status = getattr(Rhino.Geometry.IsoStatus, data["iso"])
is_reversed = True if data["is_reversed"] == "true" else False
instance.native_trim = builder.add_trim(curve, data["edge"], is_reversed, iso_status, data["vertex"])
instance.native_trim = builder.add_trim(curve, data["edge"], is_reversed, iso_status, data["start_vertex"])
return instance

# ==============================================================================
Expand All @@ -79,6 +90,18 @@ def __from_data__(cls, data, builder):
def curve(self):
return self._curve

@property
def start_vertex(self):
return self._start_vertex

@property
def end_vertex(self):
return self._end_vertex

@property
def vertices(self):
return [self.start_vertex, self.end_vertex]

@property
def is_reverse(self):
return self._curve
Expand All @@ -97,3 +120,5 @@ def native_trim(self, rhino_trim):
self._curve = RhinoNurbsCurve.from_rhino(rhino_trim.TrimCurve.ToNurbsCurve())
self._is_reversed = rhino_trim.IsReversed()
self._iso_type = int(rhino_trim.IsoStatus)
self._start_vertex = RhinoBrepVertex(rhino_trim.StartVertex)
self._end_vertex = RhinoBrepVertex(rhino_trim.EndVertex)

0 comments on commit 649a844

Please sign in to comment.