Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Similar API changes as for surfaces... #1376

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 16 in src/compas/geometry/curves/curve.py

View check run for this annotation

Codecov / codecov/patch

src/compas/geometry/curves/curve.py#L16

Added line #L16 was not covered by tests


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

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_...`)")

Check warning on line 69 in src/compas/geometry/curves/curve.py

View check run for this annotation

Codecov / codecov/patch

src/compas/geometry/curves/curve.py#L69

Added line #L69 was not covered by tests
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 @@
# ==============================================================================

@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)

Check warning on line 150 in src/compas/geometry/curves/curve.py

View check run for this annotation

Codecov / codecov/patch

src/compas/geometry/curves/curve.py#L150

Added line #L150 was not covered by tests

@classmethod
def from_obj(cls, filepath):
"""Load a curve from an OBJ file.

Parameters
----------
Expand All @@ -148,8 +166,8 @@
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 @@
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
Loading