Skip to content

Commit b1d0e60

Browse files
committed
cleanup and docstrings
1 parent fa14c16 commit b1d0e60

File tree

3 files changed

+166
-70
lines changed

3 files changed

+166
-70
lines changed

src/compas_rhino/geometry/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
66
.. currentmodule:: compas_rhino.geometry
77
8+
Classes
9+
=======
10+
11+
.. autosummary::
12+
:toctree: generated/
13+
:nosignatures:
14+
15+
RhinoNurbsCurve
16+
17+
818
Plugins
919
=======
1020
@@ -64,7 +74,7 @@
6474
from compas_rhino.conversions import RhinoSurface
6575
from compas_rhino.conversions import RhinoVector
6676

67-
BaseRhinoGeometry = RhinoGeometry
77+
from .curves import RhinoNurbsCurve
6878

6979

7080
__all__ = [
@@ -83,4 +93,6 @@
8393
'RhinoSphere',
8494
'RhinoSurface',
8595
'RhinoVector',
96+
97+
'RhinoNurbsCurve'
8698
]
Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
11
from .nurbs import RhinoNurbsCurve
22

3-
try:
4-
from compas.geometry import NurbsCurve
5-
except ImportError:
6-
pass
7-
else:
8-
from compas.plugins import plugin
9-
10-
@plugin(category='factories', requires=['Rhino'])
11-
def new_nurbscurve(cls, *args, **kwargs):
12-
return super(NurbsCurve, RhinoNurbsCurve).__new__(RhinoNurbsCurve)
13-
14-
@plugin(category='factories', requires=['Rhino'])
15-
def new_nurbscurve_from_parameters(*args, **kwargs):
16-
return RhinoNurbsCurve.from_parameters(*args, **kwargs)
17-
18-
@plugin(category='factories', requires=['Rhino'])
19-
def new_nurbscurve_from_points(*args, **kwargs):
20-
return RhinoNurbsCurve.from_points(*args, **kwargs)
21-
22-
@plugin(category='factories', requires=['Rhino'])
23-
def new_nurbscurve_from_interpolation(cls, *args, **kwargs):
24-
return RhinoNurbsCurve.from_interpolation(*args, **kwargs)
25-
26-
@plugin(category='factories', requires=['Rhino'])
27-
def new_nurbscurve_from_step(cls, *args, **kwargs):
28-
return RhinoNurbsCurve.from_step(*args, **kwargs)
3+
from compas.geometry import NurbsCurve
4+
from compas.plugins import plugin
5+
6+
7+
@plugin(category='factories', requires=['Rhino'])
8+
def new_nurbscurve(cls, *args, **kwargs):
9+
"""Create a new empty Nurbs curve."""
10+
return super(NurbsCurve, RhinoNurbsCurve).__new__(RhinoNurbsCurve)
11+
12+
13+
@plugin(category='factories', requires=['Rhino'])
14+
def new_nurbscurve_from_parameters(*args, **kwargs):
15+
"""Create a new Nurbs curve from explicit curve parameters."""
16+
return RhinoNurbsCurve.from_parameters(*args, **kwargs)
17+
18+
19+
@plugin(category='factories', requires=['Rhino'])
20+
def new_nurbscurve_from_points(*args, **kwargs):
21+
"""Construct a NURBS curve from control points.
22+
23+
Parameters
24+
----------
25+
points : list of :class:`compas.geometry.Point`
26+
The control points.
27+
degree : int
28+
The degree of the curve.
29+
is_periodic : bool, optional
30+
Flag indicating whether the curve is periodic or not.
31+
32+
Returns
33+
-------
34+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
35+
36+
"""
37+
return RhinoNurbsCurve.from_points(*args, **kwargs)
38+
39+
40+
@plugin(category='factories', requires=['Rhino'])
41+
def new_nurbscurve_from_interpolation(cls, *args, **kwargs):
42+
"""Construct a NURBS curve by interpolating a set of points.
43+
44+
Parameters
45+
----------
46+
points : list of :class:`compas.geometry.Point`
47+
The control points.
48+
precision : float, optional
49+
The required precision of the interpolation.
50+
This parameter is currently not supported.
51+
52+
Returns
53+
-------
54+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
55+
56+
"""
57+
return RhinoNurbsCurve.from_interpolation(*args, **kwargs)
58+
59+
60+
@plugin(category='factories', requires=['Rhino'])
61+
def new_nurbscurve_from_step(cls, *args, **kwargs):
62+
"""Create a new Nurbs curve from the data contained in a step file."""
63+
return RhinoNurbsCurve.from_step(*args, **kwargs)

src/compas_rhino/geometry/curves/nurbs.py

Lines changed: 92 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,25 @@ class RhinoNurbsCurve(NurbsCurve):
4242
4343
Attributes
4444
----------
45-
points: List[Point]
45+
points: list of :class:`compas.geometry.Point`
4646
The control points of the curve.
47-
weights: List[float]
47+
weights: list of float
4848
The weights of the control points.
49-
knots: List[float]
49+
knots: list of float
5050
The knot vector, without duplicates.
51-
multiplicities: List[int]
51+
multiplicities: list of int
5252
The multiplicities of the knots in the knot vector.
53-
knotsequence: List[float]
53+
knotsequence: list of float
5454
The knot vector, with repeating values according to the multiplicities.
5555
degree: int
5656
The degree of the polynomials.
5757
order: int
5858
The order of the curve.
59-
domain: Tuple[float, float]
59+
domain: tuple of float
6060
The parameter domain.
61-
start: :class:`Point`
61+
start: :class:`compas.geometry.Point`
6262
The point corresponding to the start of the parameter domain.
63-
end: :class:`Point`
63+
end: :class:`compas.geometry.Point`
6464
The point corresponding to the end of the parameter domain.
6565
is_closed: bool
6666
True if the curve is closed.
@@ -123,34 +123,66 @@ def data(self, data):
123123

124124
@classmethod
125125
def from_rhino(cls, rhino_curve):
126-
"""Construct a NURBS curve from an existing Rhino BSplineCurve."""
126+
"""Construct a NURBS curve from an existing Rhino curve.
127+
128+
Parameters
129+
----------
130+
rhino_curve : Rhino.Geometry.NurbsCurve
131+
132+
Returns
133+
-------
134+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
135+
136+
"""
127137
curve = cls()
128138
curve.rhino_curve = rhino_curve
129139
return curve
130140

131141
@classmethod
132-
def from_parameters(cls,
133-
points,
134-
weights,
135-
knots,
136-
multiplicities,
137-
degree,
138-
is_periodic=False):
139-
"""Construct a NURBS curve from explicit curve parameters."""
142+
def from_parameters(cls, points, weights, knots, multiplicities, degree, is_periodic=False):
143+
"""Construct a NURBS curve from explicit curve parameters.
144+
145+
Parameters
146+
----------
147+
points : list of :class:`compas.geometry.Point`
148+
The control points.
149+
weights : list of float
150+
The control point weights.
151+
knots : list of float
152+
The curve knots, without duplicates.
153+
multiplicities : list of int
154+
The multiplicities of the knots.
155+
degree : int
156+
The degree of the curve.
157+
is_periodic : bool, optional
158+
Flag indicating whether the curve is periodic or not.
159+
Note that this parameters is currently not supported.
160+
161+
Returns
162+
-------
163+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
164+
165+
"""
140166
curve = cls()
141-
# set periodicity => aparently not possible
142167
curve.rhino_curve = rhino_curve_from_parameters(points, weights, knots, multiplicities, degree)
143168
return curve
144169

145170
@classmethod
146171
def from_points(cls, points, degree=3, is_periodic=False):
147172
"""Construct a NURBS curve from control points.
148173
149-
This construction method is similar to the method ``Create`` of the Rhino API for NURBS curves [1]_.
150-
151-
References
174+
Parameters
152175
----------
153-
.. [1] https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_NurbsCurve_Create.htm
176+
points : list of :class:`compas.geometry.Point`
177+
The control points.
178+
degree : int
179+
The degree of the curve.
180+
is_periodic : bool, optional
181+
Flag indicating whether the curve is periodic or not.
182+
183+
Returns
184+
-------
185+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
154186
155187
"""
156188
points[:] = [point_to_rhino(point) for point in points]
@@ -162,12 +194,17 @@ def from_points(cls, points, degree=3, is_periodic=False):
162194
def from_interpolation(cls, points, precision=1e-3):
163195
"""Construct a NURBS curve by interpolating a set of points.
164196
165-
This construction method is similar to the method ``CreateHSpline`` of the Rhino API for NURBS curves [1]_.
166-
167-
References
197+
Parameters
168198
----------
169-
.. [1] https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_NurbsCurve_CreateHSpline.htm
170-
.. [2] https://dev.opencascade.org/doc/occt-7.4.0/refman/html/class_geom_a_p_i___interpolate.html
199+
points : list of :class:`compas.geometry.Point`
200+
The control points.
201+
precision : float, optional
202+
The required precision of the interpolation.
203+
This parameter is currently not supported.
204+
205+
Returns
206+
-------
207+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
171208
172209
"""
173210
curve = cls()
@@ -183,11 +220,14 @@ def from_step(cls, filepath):
183220
def from_arc(cls, arc):
184221
"""Construct a NURBS curve from an arc.
185222
186-
This construction method is similar to the method ``CreateFromArc`` of the Rhino API for NURBS curves [1]_.
187-
188-
References
223+
Parameters
189224
----------
190-
.. [1] https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_NurbsCurve_CreateFromArc.htm
225+
arc : :class:`compas.geometry.Arc`
226+
An arc geometry.
227+
228+
Returns
229+
-------
230+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
191231
192232
"""
193233
# curve = cls()
@@ -199,11 +239,14 @@ def from_arc(cls, arc):
199239
def from_circle(cls, circle):
200240
"""Construct a NURBS curve from a circle.
201241
202-
This construction method is similar to the method ``CreateFromCircle`` of the Rhino API for NURBS curves [1]_.
203-
204-
References
242+
Parameters
205243
----------
206-
.. [1] https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_NurbsCurve_CreateFromCircle.htm
244+
circle : :class:`compas.geometry.Circle`
245+
A circle geometry.
246+
247+
Returns
248+
-------
249+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
207250
208251
"""
209252
curve = cls()
@@ -214,11 +257,14 @@ def from_circle(cls, circle):
214257
def from_ellipse(cls, ellipse):
215258
"""Construct a NURBS curve from an ellipse.
216259
217-
This construction method is similar to the method ``CreateFromEllipse`` of the Rhino API for NURBS curves [1]_.
218-
219-
References
260+
Parameters
220261
----------
221-
.. [1] https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_NurbsCurve_CreateFromEllipse.htm
262+
ellipse : :class:`compas.geometry.Ellipse`
263+
An ellipse geometry.
264+
265+
Returns
266+
-------
267+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
222268
223269
"""
224270
curve = cls()
@@ -229,11 +275,14 @@ def from_ellipse(cls, ellipse):
229275
def from_line(cls, line):
230276
"""Construct a NURBS curve from a line.
231277
232-
This construction method is similar to the method ``CreateFromLine`` of the Rhino API for NURBS curves [1]_.
233-
234-
References
278+
Parameters
235279
----------
236-
.. [1] https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_NurbsCurve_CreateFromLine.htm
280+
line : :class:`compas.geometry.Line`
281+
A line geometry.
282+
283+
Returns
284+
-------
285+
:class:`compas_rhino.geometry.RhinoNurbsCurve`
237286
238287
"""
239288
curve = cls()

0 commit comments

Comments
 (0)