Skip to content

Commit 7803b29

Browse files
authored
Merge pull request #1376 from compas-dev/curve-api
Similar API changes as for surfaces...
2 parents 8007489 + bb3b72d commit 7803b29

File tree

10 files changed

+287
-366
lines changed

10 files changed

+287
-366
lines changed

CHANGELOG.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
* Added `compas_rhino.geometry.surfaces.nurbs.NurbsSurface.from_frame`.
3030
* Added `compas_rhino.geometry.surfaces.nurbs.NurbsSurface.from_sphere`.
3131
* Added `compas_rhino.geometry.surfaces.nurbs.NurbsSurface.from_torus`.
32+
* Added `compas.geometry.curves.curve.Curve.from_native`.
33+
* Added `compas_rhino.geometry.curves.curve.Curve.from_native`.
34+
* Added `compas_rhino.geometry.curves.nurbs.NurbsCurve.from_native`.
3235

3336
### Changed
3437

3538
* Fixed bug in `compas.geometry.curves.curve.Curve.reversed` by adding missing parenthesis.
3639
* Fixed all doctests so we can run `invoke test --doctest`.
37-
* Changed `compas.geometry.surfaces.surface.Surface.__new__` to prevent instantiation of `compas.geometry.surfaces.surface.Surface` directly.
38-
* Changed `compas.geometry.surfaces.nurbs.NurbsSurface.__new__` to prevent instantiation of `compas.geometry.surfaces.nurbs.NurbsSurface` directly.
40+
* Changed `compas.geometry.surfaces.surface.Surface.__new__` to prevent instantiation of `Surface` directly.
41+
* Changed `compas.geometry.surfaces.nurbs.NurbsSurface.__new__` to prevent instantiation of `NurbsSurface` directly.
3942
* Fixed bug in `compas.geometry.surfaces.nurbs.NurbsSurface.__data__`.
40-
* Changed `compas.geometry.surfaces.nurbs.new_nurbssurface_from_...` to `compas.geometry.surfaces.nurbs.nurbssurface_from_...`.
43+
* Changed `compas.geometry.surfaces.nurbs.new_nurbssurface_from_...` to `nurbssurface_from_...`.
44+
* Changed `compas.geometry.curves.curve.Curve.__new__` to prevent instantiation of `Curve` directly.
45+
* Changed `compas.geometry.curves.nurbs.new_nurbscurve_from_...` to `nurbscurve_from_...`.
46+
* Changed `compas.geometry.curves.nurbs.NurbsCurve.__new__` to prevent instantiation of `NurbsCurve` directly.
47+
* Changed `compas_rhino.geometry.curves.new_nurbscurve_from_...` to `nurbscurve_from_...`.
4148

4249
### Removed
4350

@@ -58,6 +65,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5865
* Removed `compas_rhino.geometry.surfaces.surface.Surface.from_frame`.
5966
* Removed `compas_rhino.geometry.surfaces.surface.Surface.from_sphere`.
6067
* Removed `compas_rhino.geometry.surfaces.surface.Surface.from_torus`.
68+
* Removed `compas.geometry.curves.arc.Arc.__new__`.
69+
* Removed `compas.geometry.curves.bezier.Bezier.__new__`.
70+
* Removed `compas.geometry.curves.conic.Conic.__new__`.
71+
* Removed `compas.geometry.curves.polyline.Polyline.__new__`.
72+
* Removed `compas.geometry.curves.curve.new_curve`.
73+
* Removed `compas.geometry.curves.curve.new_nurbscurve`.
74+
* Removed `compas_rhino.geometry.curves.new_curve`.
75+
* Removed `compas_rhino.geometry.curves.new_nurbscurve`.
6176

6277
## [2.2.1] 2024-06-25
6378

src/compas/geometry/curves/arc.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ class Arc(Curve):
116116
117117
"""
118118

119-
# overwriting the __new__ method is necessary
120-
# to avoid triggering the plugin mechanism of the base curve class
121-
def __new__(cls, *args, **kwargs):
122-
curve = object.__new__(cls)
123-
curve.__init__(*args, **kwargs)
124-
return curve
125-
126119
DATASCHEMA = {
127120
"value": {
128121
"type": "object",

src/compas/geometry/curves/bezier.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ class Bezier(Curve):
162162
163163
"""
164164

165-
# overwriting the __new__ method is necessary
166-
# to avoid triggering the plugin mechanism of the base curve class
167-
def __new__(cls, *args, **kwargs):
168-
curve = object.__new__(cls)
169-
curve.__init__(*args, **kwargs)
170-
return curve
171-
172165
DATASCHEMA = {
173166
"type": "object",
174167
"properties": {

src/compas/geometry/curves/conic.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,3 @@
77

88
class Conic(Curve):
99
"""Base class for curves that are conic sections."""
10-
11-
# overwriting the __new__ method is necessary
12-
# to avoid triggering the plugin mechanism of the base curve class
13-
def __new__(cls, *args, **kwargs):
14-
curve = object.__new__(cls)
15-
curve.__init__(*args, **kwargs)
16-
return curve

src/compas/geometry/curves/curve.py

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
from compas.geometry import Plane
88
from compas.geometry import Transformation
99
from compas.itertools import linspace
10+
from compas.plugins import PluginNotInstalledError
1011
from compas.plugins import pluggable
1112

1213

1314
@pluggable(category="factories")
14-
def new_curve(cls, *args, **kwargs):
15-
curve = object.__new__(cls)
16-
curve.__init__(*args, **kwargs)
17-
return curve
15+
def curve_from_native(cls, *args, **kwargs):
16+
raise PluginNotInstalledError
1817

1918

2019
class Curve(Geometry):
@@ -66,7 +65,9 @@ class Curve(Geometry):
6665
"""
6766

6867
def __new__(cls, *args, **kwargs):
69-
return new_curve(cls, *args, **kwargs)
68+
if cls is Curve:
69+
raise TypeError("Making an instance of `Curve` using `Curve()` is not allowed. Please use one of the factory methods instead (`Curve.from_...`)")
70+
return object.__new__(cls)
7071

7172
def __init__(self, frame=None, name=None):
7273
super(Curve, self).__init__(name=name)
@@ -132,8 +133,25 @@ def is_periodic(self):
132133
# ==============================================================================
133134

134135
@classmethod
135-
def from_step(cls, filepath):
136-
"""Load a curve from a STP file.
136+
def from_native(cls, curve):
137+
"""Construct a parametric curve from a native curve geometry.
138+
139+
Parameters
140+
----------
141+
curve
142+
A native curve object.
143+
144+
Returns
145+
-------
146+
:class:`compas.geometry.Curve`
147+
A COMPAS curve.
148+
149+
"""
150+
return curve_from_native(cls, curve)
151+
152+
@classmethod
153+
def from_obj(cls, filepath):
154+
"""Load a curve from an OBJ file.
137155
138156
Parameters
139157
----------
@@ -148,8 +166,8 @@ def from_step(cls, filepath):
148166
raise NotImplementedError
149167

150168
@classmethod
151-
def from_obj(cls, filepath):
152-
"""Load a curve from an OBJ file.
169+
def from_step(cls, filepath):
170+
"""Load a curve from a STP file.
153171
154172
Parameters
155173
----------
@@ -465,47 +483,6 @@ def reversed(self):
465483
copy.reverse()
466484
return copy
467485

468-
# def space(self, n=10):
469-
# """Compute evenly spaced parameters over the curve domain.
470-
471-
# Parameters
472-
# ----------
473-
# n : int, optional
474-
# The number of values in the parameter space.
475-
476-
# Returns
477-
# -------
478-
# list[float]
479-
480-
# See Also
481-
# --------
482-
# :meth:`locus`
483-
484-
# """
485-
# start, end = self.domain
486-
# return linspace(start, end, n)
487-
488-
# def locus(self, resolution=100):
489-
# """Compute the locus of points on the curve.
490-
491-
# Parameters
492-
# ----------
493-
# resolution : int
494-
# The number of intervals at which a point on the
495-
# curve should be computed.
496-
497-
# Returns
498-
# -------
499-
# list[:class:`compas.geometry.Point`]
500-
# Points along the curve.
501-
502-
# See Also
503-
# --------
504-
# :meth:`space`
505-
506-
# """
507-
# return [self.point_at(t) for t in self.space(resolution)]
508-
509486
def closest_point(self, point, return_parameter=False):
510487
"""Compute the closest point on the curve to a given point.
511488

0 commit comments

Comments
 (0)