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

helpers use weakref #350

Merged
merged 4 commits into from
Feb 5, 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
10 changes: 8 additions & 2 deletions splinepy/helpme/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ class Checker:
Parent spline, that is to be checked
"""

__slots__ = ("_helpee",)

def __init__(self, spl):
self._spline = spl
self._helpee = spl

def valid_queries(self, queries):
return valid_queries(self._spline, queries)
return valid_queries(self._helpee, queries)


# Use function docstrings in Checker functions
Checker.valid_queries.__doc__ = valid_queries.__doc__
12 changes: 7 additions & 5 deletions splinepy/helpme/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,20 +956,22 @@ class Creator:
>>> spline_faces = my_spline.create.extrude(vector=[3, 1, 3])
"""

__slots__ = ("_helpee",)

def __init__(self, spl):
self.spline = spl
self._helpee = spl

def extruded(self, *args, **kwargs):
return extruded(self.spline, *args, **kwargs)
return extruded(self._helpee, *args, **kwargs)

def revolved(self, *args, **kwargs):
return revolved(self.spline, *args, **kwargs)
return revolved(self._helpee, *args, **kwargs)

def parametric_view(self, *args, **kwargs):
return parametric_view(self.spline, *args, **kwargs)
return parametric_view(self._helpee, *args, **kwargs)

def determinant_spline(self, *args, **kwargs):
return determinant_spline(self.spline, *args, **kwargs)
return determinant_spline(self._helpee, *args, **kwargs)


# Use function docstrings in Extractor functions
Expand Down
32 changes: 17 additions & 15 deletions splinepy/helpme/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,37 +535,39 @@ class Extractor:
>>> spline_faces = my_spline.extract.faces()
"""

__slots__ = ("_helpee",)

def __init__(self, spl):
from splinepy import Multipatch as _Multipatch
from splinepy import Spline as _Spline

if not isinstance(spl, (_Spline, _Multipatch)):
raise ValueError("Extractor expects a Spline or Multipatch type")
self._spline = spl
self._helpee = spl

def edges(self, *args, **kwargs):
return edges(self._spline, *args, **kwargs)
return edges(self._helpee, *args, **kwargs)

def faces(self, *args, **kwargs):
return faces(self._spline, *args, **kwargs)
return faces(self._helpee, *args, **kwargs)

def volumes(self, *args, **kwargs):
return volumes(self._spline, *args, **kwargs)
return volumes(self._helpee, *args, **kwargs)

def control_points(self):
return control_points(self._spline)
return control_points(self._helpee)

def control_edges(self):
return control_edges(self._spline)
return control_edges(self._helpee)

def control_faces(self):
return control_faces(self._spline)
return control_faces(self._helpee)

def control_volumes(self):
return control_volumes(self._spline)
return control_volumes(self._helpee)

def control_mesh(self):
return control_mesh(self._spline)
return control_mesh(self._helpee)

def beziers(self):
"""
Expand All @@ -581,12 +583,12 @@ def beziers(self):
List of all individual bezier patches representing the non-zero
knot-spans
"""
if not self._spline.has_knot_vectors:
return [self._spline]
return self._spline.extract_bezier_patches()
if not self._helpee.has_knot_vectors:
return [self._helpee]
return self._helpee.extract_bezier_patches()

def boundaries(self, *args, **kwargs):
return boundaries(self._spline, *args, **kwargs)
return boundaries(self._helpee, *args, **kwargs)

def spline(self, splitting_plane=None, interval=None):
"""Extract a spline from a spline.
Expand All @@ -612,12 +614,12 @@ def spline(self, splitting_plane=None, interval=None):
splitting_plane = dict(
sorted(splitting_plane.items(), key=lambda x: x[0])[::-1]
)
spline_copy = self._spline.copy()
spline_copy = self._helpee.copy()
for key, item in splitting_plane.items():
spline_copy = spline(spline_copy, key, item)
return spline_copy
else:
return spline(self._spline, splitting_plane, interval)
return spline(self._helpee, splitting_plane, interval)


# Use function docstrings in Extractor functions
Expand Down
2 changes: 1 addition & 1 deletion splinepy/helpme/ffd.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def show(self, **kwargs):
raise ValueError("Please set a mesh before calling show()")
return_showable = kwargs.pop("return_showable", False)
return_gustaf = kwargs.pop("return_gustaf", False)
title = kwargs.pop("title", "gustaf - FFD")
title = kwargs.pop("title", "FFD")

if return_gustaf and return_showable:
raise ValueError(
Expand Down
8 changes: 5 additions & 3 deletions splinepy/helpme/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def volume(spline, orders=None):

# Check i_nput type
if not isinstance(spline, _Spline):
raise NotImplementedError("Extrude only works for splines")
raise NotImplementedError("volume integration only works for splines")

# Determine integration points
positions = []
Expand Down Expand Up @@ -125,8 +125,10 @@ class Integrator:
Spline parent
"""

__slots__ = ("_helpee",)

def __init__(self, spl):
self.spline = spl
self._helpee = spl

def volume(self, *args, **kwargs):
return volume(self.spline, *args, **kwargs)
return volume(self._helpee, *args, **kwargs)
17 changes: 7 additions & 10 deletions splinepy/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def _get_helper(spl, attr_name, helper_class):
if attr is not None: # hasattr
return attr

# don't have attr - create and set
# if attr doesn't exist, create one and save to its member defined in
# slots
helper_obj = helper_class(spl)
setattr(spl, attr_name, helper_obj)

Expand Down Expand Up @@ -385,10 +386,6 @@ class Spline(_SplinepyBase, _core.PySpline):
"""

__slots__ = (
"_extractor",
"_checker",
"_creator",
"_integrator",
"_show_options",
"_spline_data",
)
Expand Down Expand Up @@ -566,7 +563,7 @@ def extract(self):
--------
extractor: Extractor
"""
return _get_helper(self, "_extractor", _Extractor)
return _Extractor(self)

@property
def check(self):
Expand All @@ -583,9 +580,9 @@ def check(self):

Returns
--------
extractor: Extractor
checker: Checker
"""
return _get_helper(self, "_checker", _Checker)
return _Checker(self)

@property
def integrate(self):
Expand All @@ -607,7 +604,7 @@ def integrate(self):
--------
integrator: Integrator
"""
return _get_helper(self, "_integrator", _Integrator)
return _Integrator(self)

@property
def create(self):
Expand All @@ -626,7 +623,7 @@ def create(self):
-------
creator: spline.Creator
"""
return _get_helper(self, "_creator", _Creator)
return _Creator(self)

@property
def show_options(self):
Expand Down
Loading