Skip to content

Commit

Permalink
Merge pull request #1376 from compas-dev/curve-api
Browse files Browse the repository at this point in the history
Similar API changes as for surfaces...
  • Loading branch information
tomvanmele authored Jul 4, 2024
2 parents 8007489 + bb3b72d commit 7803b29
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 366 deletions.
21 changes: 18 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `compas_rhino.geometry.surfaces.nurbs.NurbsSurface.from_frame`.
* Added `compas_rhino.geometry.surfaces.nurbs.NurbsSurface.from_sphere`.
* Added `compas_rhino.geometry.surfaces.nurbs.NurbsSurface.from_torus`.
* Added `compas.geometry.curves.curve.Curve.from_native`.
* Added `compas_rhino.geometry.curves.curve.Curve.from_native`.
* Added `compas_rhino.geometry.curves.nurbs.NurbsCurve.from_native`.

### Changed

* Fixed bug in `compas.geometry.curves.curve.Curve.reversed` by adding missing parenthesis.
* Fixed all doctests so we can run `invoke test --doctest`.
* Changed `compas.geometry.surfaces.surface.Surface.__new__` to prevent instantiation of `compas.geometry.surfaces.surface.Surface` directly.
* Changed `compas.geometry.surfaces.nurbs.NurbsSurface.__new__` to prevent instantiation of `compas.geometry.surfaces.nurbs.NurbsSurface` directly.
* Changed `compas.geometry.surfaces.surface.Surface.__new__` to prevent instantiation of `Surface` directly.
* Changed `compas.geometry.surfaces.nurbs.NurbsSurface.__new__` to prevent instantiation of `NurbsSurface` directly.
* Fixed bug in `compas.geometry.surfaces.nurbs.NurbsSurface.__data__`.
* Changed `compas.geometry.surfaces.nurbs.new_nurbssurface_from_...` to `compas.geometry.surfaces.nurbs.nurbssurface_from_...`.
* Changed `compas.geometry.surfaces.nurbs.new_nurbssurface_from_...` to `nurbssurface_from_...`.
* Changed `compas.geometry.curves.curve.Curve.__new__` to prevent instantiation of `Curve` directly.
* Changed `compas.geometry.curves.nurbs.new_nurbscurve_from_...` to `nurbscurve_from_...`.
* Changed `compas.geometry.curves.nurbs.NurbsCurve.__new__` to prevent instantiation of `NurbsCurve` directly.
* Changed `compas_rhino.geometry.curves.new_nurbscurve_from_...` to `nurbscurve_from_...`.

### Removed

Expand All @@ -58,6 +65,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Removed `compas_rhino.geometry.surfaces.surface.Surface.from_frame`.
* Removed `compas_rhino.geometry.surfaces.surface.Surface.from_sphere`.
* Removed `compas_rhino.geometry.surfaces.surface.Surface.from_torus`.
* Removed `compas.geometry.curves.arc.Arc.__new__`.
* Removed `compas.geometry.curves.bezier.Bezier.__new__`.
* Removed `compas.geometry.curves.conic.Conic.__new__`.
* Removed `compas.geometry.curves.polyline.Polyline.__new__`.
* Removed `compas.geometry.curves.curve.new_curve`.
* Removed `compas.geometry.curves.curve.new_nurbscurve`.
* Removed `compas_rhino.geometry.curves.new_curve`.
* Removed `compas_rhino.geometry.curves.new_nurbscurve`.

## [2.2.1] 2024-06-25

Expand Down
7 changes: 0 additions & 7 deletions src/compas/geometry/curves/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ class Arc(Curve):
"""

# overwriting the __new__ method is necessary
# to avoid triggering the plugin mechanism of the base curve class
def __new__(cls, *args, **kwargs):
curve = object.__new__(cls)
curve.__init__(*args, **kwargs)
return curve

DATASCHEMA = {
"value": {
"type": "object",
Expand Down
7 changes: 0 additions & 7 deletions src/compas/geometry/curves/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ class Bezier(Curve):
"""

# overwriting the __new__ method is necessary
# to avoid triggering the plugin mechanism of the base curve class
def __new__(cls, *args, **kwargs):
curve = object.__new__(cls)
curve.__init__(*args, **kwargs)
return curve

DATASCHEMA = {
"type": "object",
"properties": {
Expand Down
7 changes: 0 additions & 7 deletions src/compas/geometry/curves/conic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,3 @@

class Conic(Curve):
"""Base class for curves that are conic sections."""

# overwriting the __new__ method is necessary
# to avoid triggering the plugin mechanism of the base curve class
def __new__(cls, *args, **kwargs):
curve = object.__new__(cls)
curve.__init__(*args, **kwargs)
return curve
77 changes: 27 additions & 50 deletions src/compas/geometry/curves/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from compas.geometry import Plane
from compas.geometry import Transformation
from compas.itertools import linspace
from compas.plugins import PluginNotInstalledError
from compas.plugins import pluggable


@pluggable(category="factories")
def new_curve(cls, *args, **kwargs):
curve = object.__new__(cls)
curve.__init__(*args, **kwargs)
return curve
def curve_from_native(cls, *args, **kwargs):
raise PluginNotInstalledError


class Curve(Geometry):
Expand Down Expand Up @@ -66,7 +65,9 @@ class Curve(Geometry):
"""

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

def __init__(self, frame=None, name=None):
super(Curve, self).__init__(name=name)
Expand Down Expand Up @@ -132,8 +133,25 @@ def is_periodic(self):
# ==============================================================================

@classmethod
def from_step(cls, filepath):
"""Load a curve from a STP file.
def from_native(cls, curve):
"""Construct a parametric curve from a native curve geometry.
Parameters
----------
curve
A native curve object.
Returns
-------
:class:`compas.geometry.Curve`
A COMPAS curve.
"""
return curve_from_native(cls, curve)

@classmethod
def from_obj(cls, filepath):
"""Load a curve from an OBJ file.
Parameters
----------
Expand All @@ -148,8 +166,8 @@ def from_step(cls, filepath):
raise NotImplementedError

@classmethod
def from_obj(cls, filepath):
"""Load a curve from an OBJ file.
def from_step(cls, filepath):
"""Load a curve from a STP file.
Parameters
----------
Expand Down Expand Up @@ -465,47 +483,6 @@ def reversed(self):
copy.reverse()
return copy

# def space(self, n=10):
# """Compute evenly spaced parameters over the curve domain.

# Parameters
# ----------
# n : int, optional
# The number of values in the parameter space.

# Returns
# -------
# list[float]

# See Also
# --------
# :meth:`locus`

# """
# start, end = self.domain
# return linspace(start, end, n)

# def locus(self, resolution=100):
# """Compute the locus of points on the curve.

# Parameters
# ----------
# resolution : int
# The number of intervals at which a point on the
# curve should be computed.

# Returns
# -------
# list[:class:`compas.geometry.Point`]
# Points along the curve.

# See Also
# --------
# :meth:`space`

# """
# return [self.point_at(t) for t in self.space(resolution)]

def closest_point(self, point, return_parameter=False):
"""Compute the closest point on the curve to a given point.
Expand Down
Loading

0 comments on commit 7803b29

Please sign in to comment.