Skip to content

Commit f24872a

Browse files
authored
Merge pull request #1410 from compas-dev/trim_vertices
Trim vertices
2 parents 915d46c + 8692bd5 commit f24872a

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added attribute `start_vertex` to `compas.geometry.BrepTrim`.
13+
* Added attribute `end_vertex` to `compas.geometry.BrepTrim`.
14+
* Added attribute `vertices` to `compas.geometry.BrepTrim`.
15+
* Added attribute `start_vertex` to `compas_rhino.geometry.RhinoBrepTrim`.
16+
* Added attribute `start_vertex` to `compas_rhino.geometry.RhinoBrepTrim`.
17+
* Added attribute `vertices` to `compas_rhino.geometry.RhinoBrepTrim`.
18+
1219
### Changed
1320

1421
* Fixed `PluginNotInstalledError` when using `Brep.from_boolean_*` in Rhino.
22+
* Added support for `Polyline` as input for `compas_rhino.Brep.from_extrusion`.
1523

1624
### Removed
1725

src/compas/geometry/brep/brep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def from_extrusion(cls, curve, vector, cap_ends=True):
392392
393393
Parameters
394394
----------
395-
curve : :class:`compas.geometry.Curve`
395+
curve : :class:`compas.geometry.Curve` or :class:`compas.geometry.Polyline`
396396
The curve to extrude
397397
vector : :class:`compas.geometry.Vector`
398398
The vector to extrude the curve by

src/compas/geometry/brep/trim.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class BrepTrim(Data):
2626
True if this trim is reversed from its associated edge curve and False otherwise.
2727
native_trim : Any
2828
The underlying trim object. Type is backend-dependent.
29+
start_vertex : Any, read-only
30+
The start vertex of this trim.
31+
end_vertex : Any, read-only
32+
The end vertex of this trim.
33+
vertices : list[Any], read-only
2934
3035
"""
3136

@@ -44,3 +49,15 @@ def is_reversed(self):
4449
@property
4550
def native_trim(self):
4651
raise NotImplementedError
52+
53+
@property
54+
def start_vertex(self):
55+
raise NotImplementedError
56+
57+
@property
58+
def end_vertex(self):
59+
raise NotImplementedError
60+
61+
@property
62+
def vertices(self):
63+
raise NotImplementedError

src/compas_rhino/geometry/brep/brep.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from compas.geometry import Frame
1111
from compas.geometry import Plane
1212
from compas.geometry import Point
13+
from compas.geometry import Polyline
1314
from compas.tolerance import TOL
1415
from compas_rhino.conversions import box_to_rhino
1516
from compas_rhino.conversions import curve_to_compas
@@ -19,6 +20,7 @@
1920
from compas_rhino.conversions import mesh_to_rhino
2021
from compas_rhino.conversions import plane_to_rhino
2122
from compas_rhino.conversions import point_to_rhino
23+
from compas_rhino.conversions import polyline_to_rhino_curve
2224
from compas_rhino.conversions import sphere_to_rhino
2325
from compas_rhino.conversions import transformation_to_rhino
2426
from compas_rhino.conversions import vector_to_rhino
@@ -223,7 +225,7 @@ def from_extrusion(cls, curve, vector, cap_ends=True):
223225
224226
Parameters
225227
----------
226-
curve : :class:`~compas.geometry.Curve`
228+
curve : :class:`~compas.geometry.Curve` or :class:`~compas.geometry.Polyline`
227229
The curve to extrude.
228230
vector : :class:`~compas.geometry.Vector`
229231
The vector to extrude the curve along.
@@ -235,7 +237,11 @@ def from_extrusion(cls, curve, vector, cap_ends=True):
235237
:class:`~compas_rhino.geometry.RhinoBrep`
236238
237239
"""
238-
extrusion = Rhino.Geometry.Surface.CreateExtrusion(curve_to_rhino(curve), vector_to_rhino(vector))
240+
if isinstance(curve, Polyline):
241+
rhino_curve = polyline_to_rhino_curve(curve)
242+
else:
243+
rhino_curve = curve_to_rhino(curve)
244+
extrusion = Rhino.Geometry.Surface.CreateExtrusion(rhino_curve, vector_to_rhino(vector))
239245
if extrusion is None:
240246
raise BrepError("Failed to create extrusion from curve: {} and vector: {}".format(curve, vector))
241247
rhino_brep = extrusion.ToBrep()

src/compas_rhino/geometry/brep/trim.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from compas.geometry import BrepTrim
88
from compas_rhino.geometry import RhinoNurbsCurve
99

10+
from .vertex import RhinoBrepVertex
11+
1012

1113
class RhinoBrepTrim(BrepTrim):
12-
"""An interface for a Brep Trim
14+
"""Trims hold topological information about how the edges of a Brep face are are organized.
1315
1416
Attributes
1517
----------
@@ -21,6 +23,12 @@ class RhinoBrepTrim(BrepTrim):
2123
True if this trim is reversed from its associated edge curve and False otherwise.
2224
native_trim : :class:`Rhino.Geometry.BrepTrim`
2325
The underlying Rhino BrepTrim object.
26+
start_vertex : :class:`compas_rhino.geometry.RhinoBrepVertex`, read-only
27+
The start vertex of this trim.
28+
end_vertex : :class:`compas_rhino.geometry.RhinoBrepVertex`, read-only
29+
The end vertex of this trim.
30+
vertices : list[:class:`compas_rhino.geometry.RhinoBrepVertex`], read-only
31+
The list of vertices which comprise this trim (start and end).
2432
2533
"""
2634

@@ -30,6 +38,8 @@ def __init__(self, rhino_trim=None):
3038
self._curve = None
3139
self._is_reversed = None
3240
self._iso_type = None
41+
self._start_vertex = None
42+
self._end_vertex = None
3343
if rhino_trim:
3444
self.native_trim = rhino_trim
3545

@@ -40,7 +50,8 @@ def __init__(self, rhino_trim=None):
4050
@property
4151
def __data__(self):
4252
return {
43-
"vertex": self._trim.StartVertex.VertexIndex,
53+
"start_vertex": self._trim.StartVertex.VertexIndex,
54+
"end_vertex": self._trim.EndVertex.VertexIndex,
4455
"edge": self._trim.Edge.EdgeIndex if self._trim.Edge else -1, # singular trims have no associated edge
4556
"curve": RhinoNurbsCurve.from_rhino(self._trim.TrimCurve.ToNurbsCurve()).__data__,
4657
"iso": str(self._trim.IsoStatus),
@@ -68,7 +79,7 @@ def __from_data__(cls, data, builder):
6879
curve = RhinoNurbsCurve.__from_data__(data["curve"]).rhino_curve
6980
iso_status = getattr(Rhino.Geometry.IsoStatus, data["iso"])
7081
is_reversed = True if data["is_reversed"] == "true" else False
71-
instance.native_trim = builder.add_trim(curve, data["edge"], is_reversed, iso_status, data["vertex"])
82+
instance.native_trim = builder.add_trim(curve, data["edge"], is_reversed, iso_status, data["start_vertex"])
7283
return instance
7384

7485
# ==============================================================================
@@ -79,6 +90,18 @@ def __from_data__(cls, data, builder):
7990
def curve(self):
8091
return self._curve
8192

93+
@property
94+
def start_vertex(self):
95+
return self._start_vertex
96+
97+
@property
98+
def end_vertex(self):
99+
return self._end_vertex
100+
101+
@property
102+
def vertices(self):
103+
return [self.start_vertex, self.end_vertex]
104+
82105
@property
83106
def is_reverse(self):
84107
return self._curve
@@ -97,3 +120,5 @@ def native_trim(self, rhino_trim):
97120
self._curve = RhinoNurbsCurve.from_rhino(rhino_trim.TrimCurve.ToNurbsCurve())
98121
self._is_reversed = rhino_trim.IsReversed()
99122
self._iso_type = int(rhino_trim.IsoStatus)
123+
self._start_vertex = RhinoBrepVertex(rhino_trim.StartVertex)
124+
self._end_vertex = RhinoBrepVertex(rhino_trim.EndVertex)

0 commit comments

Comments
 (0)