Skip to content

Commit

Permalink
Copy of C++ spline lead to 2 splines sharing core
Browse files Browse the repository at this point in the history
This is more readable and avoids copy bugs. Transformation operations should always end in copies of the original,
regardless of wheteher type was changed or not
  • Loading branch information
jzwar committed Jun 29, 2023
1 parent 807b7dc commit b5e3a71
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions splinepy/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ def __init__(self, degrees=None, control_points=None, spline=None):

@property
def bezier(self):
return settings.NAME_TO_TYPE["Bezier"](spline=self)
return settings.NAME_TO_TYPE["Bezier"](**self.todict())

@property
def rationalbezier(self):
return settings.NAME_TO_TYPE["RationalBezier"](
**self.todict(), weights=np.ones((len(self.cps), 1))
**self.todict(), weights=np.ones((self.cps.shape[0], 1))
)

@property
Expand Down
2 changes: 1 addition & 1 deletion splinepy/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def approximate_surface(

@property
def bspline(self):
return settings.NAME_TO_TYPE["BSpline"](spline=self)
return settings.NAME_TO_TYPE["BSpline"](**self.todict())

@property
def nurbs(self):
Expand Down
4 changes: 3 additions & 1 deletion splinepy/microstructure/microstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ def create(self, closing_face=None, knot_span_wise=None, **kwargs):

# Prepare the deformation function
# Transform into a non-uniform splinetype and make sure to work on copy
if hasattr(self._deformation_function, "bspline"):
if "BSpline" in self._deformation_function.whatami:
deformation_function_copy = self._deformation_function.copy()
elif hasattr(self._deformation_function, "bspline"):
deformation_function_copy = self._deformation_function.bspline
else:
deformation_function_copy = self._deformation_function.nurbs
Expand Down
2 changes: 1 addition & 1 deletion splinepy/nurbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ def __init__(

@property
def nurbs(self):
return settings.NAME_TO_TYPE["NURBS"](spline=self)
return settings.NAME_TO_TYPE["NURBS"](**self.todict())

0 comments on commit b5e3a71

Please sign in to comment.