55from compas_rhino .geometry import RhinoNurbsCurve
66from compas_rhino .conversions import curve_to_compas_line
77from compas_rhino .conversions import curve_to_compas_circle
8+ from compas_rhino .conversions import curve_to_compas_ellipse
89from compas_rhino .conversions import line_to_rhino_curve
910from compas_rhino .conversions import circle_to_rhino_curve
11+ from compas_rhino .conversions import ellipse_to_rhino_curve
12+
1013
1114from .vertex import RhinoBrepVertex
1215
1316
1417class RhinoBrepEdge (BrepEdge ):
15- """A wrapper for Rhino.Geometry.BrepEdge
18+ """A wrapper for Rhino.Geometry.BrepEdge.
19+
20+ The expected native type here is a Rhino.Geometry.BrepTrim.
21+ a BrepTrim holds a reference to its associated BrepEdge as well as its start a end vertices
22+ in a correct topological order (!).
1623
1724 Attributes
1825 ----------
1926 curve : :class:`Rhino.Geometry.Curve3D`
2027 The underlying geometry of this edge.
2128 start_vertex : :class:`~compas_rhino.geometry.RhinoBrepVertex`, read-only
22- The start vertex of this edge.
29+ The start vertex of this edge (taken from BrepTrim) .
2330 end_vertex : :class:`~compas_rhino.geometry.RhinoBrepVertex`, read-only
24- The end vertex of this edge.
31+ The end vertex of this edge (taken from BrepTrim) .
2532 vertices : list[:class:`~compas_rhino.geometry.RhinoBrepVertex`], read-only
2633 The list of vertices which comprise this edge (start and end)
2734 is_circle : bool, read-only
@@ -31,20 +38,20 @@ class RhinoBrepEdge(BrepEdge):
3138
3239 """
3340
34- def __init__ (self , rhino_edge = None ):
41+ def __init__ (self , rhino_trim = None ):
3542 super (RhinoBrepEdge , self ).__init__ ()
3643 self ._edge = None
3744 self ._curve = None
3845 self ._start_vertex = None
3946 self ._end_vertex = None
40- if rhino_edge :
41- self ._set_edge (rhino_edge )
47+ if rhino_trim :
48+ self ._set_edge (rhino_trim )
4249
43- def _set_edge (self , native_edge ):
44- self ._edge = native_edge
50+ def _set_edge (self , rhino_trim ):
51+ self ._edge = rhino_trim . Edge
4552 self ._curve = self ._edge .EdgeCurve
46- self ._start_vertex = RhinoBrepVertex (self . _edge .StartVertex )
47- self ._end_vertex = RhinoBrepVertex (self . _edge .EndVertex )
53+ self ._start_vertex = RhinoBrepVertex (rhino_trim .StartVertex )
54+ self ._end_vertex = RhinoBrepVertex (rhino_trim .EndVertex )
4855
4956 # ==============================================================================
5057 # Data
@@ -58,13 +65,16 @@ def data(self):
5865 elif self .is_circle :
5966 type_ = "circle"
6067 curve = curve_to_compas_circle (self ._curve )
68+ elif self .is_ellipse :
69+ type_ = "ellipse"
70+ curve = curve_to_compas_ellipse (self ._curve )
6171 else :
6272 type_ = "nurbs"
6373 curve = RhinoNurbsCurve .from_rhino (self ._curve )
6474 return {
6575 "type" : type_ ,
6676 "value" : curve .data ,
67- "points" : [self ._start_vertex .point .data , self ._end_vertex .point .data ],
77+ "points" : [self .start_vertex .point .data , self .end_vertex .point .data ],
6878 }
6979
7080 @data .setter
@@ -74,9 +84,11 @@ def data(self, value):
7484 self ._curve = line_to_rhino_curve (Line .from_data (value ["value" ])) # this returns a Nurbs Curve, why?
7585 elif curve_type == "circle" :
7686 self ._curve = circle_to_rhino_curve (Circle .from_data (value ["value" ])) # this returns a Nurbs Curve, why?
87+ elif curve_type == "ellipse" :
88+ self ._curve = ellipse_to_rhino_curve (value ["value" ])
7789 else :
7890 self ._curve = RhinoNurbsCurve .from_data (value ["value" ]).rhino_curve
79- # TODO: can a single edge be defined with more than start and end vertices?
91+
8092 self ._start_vertex , self ._end_vertex = RhinoBrepVertex (), RhinoBrepVertex ()
8193 self ._start_vertex ._point = Point .from_data (value ["points" ][0 ])
8294 self ._end_vertex ._point = Point .from_data (value ["points" ][1 ])
@@ -99,7 +111,7 @@ def end_vertex(self):
99111
100112 @property
101113 def vertices (self ):
102- return [self ._start_vertex , self ._end_vertex ]
114+ return [self .start_vertex , self .end_vertex ]
103115
104116 @property
105117 def is_circle (self ):
@@ -108,3 +120,7 @@ def is_circle(self):
108120 @property
109121 def is_line (self ):
110122 return self ._curve .IsLinear ()
123+
124+ @property
125+ def is_ellipse (self ):
126+ return self ._curve .IsEllipse ()
0 commit comments