77from compas .geometry import Plane
88from compas .geometry import Transformation
99from compas .itertools import linspace
10+ from compas .plugins import PluginNotInstalledError
1011from 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
2019class 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