Skip to content

Commit 194f946

Browse files
committed
prepare for callbacks on modification of ctrlpts and weights arrays
1 parent c161fbb commit 194f946

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

geomdl/NURBS.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def ctrlpts(self):
127127
# Populate the cache, if necessary
128128
if not self._cache['ctrlpts']:
129129
c, w = compatibility.separate_ctrlpts_weights(self._control_points)
130-
self._cache['ctrlpts'] = [crd for crd in c]
131-
self._cache['weights'] = w
130+
self._cache['ctrlpts'] = self._array_type(iter(c))
131+
self._cache['weights'] = self._array_type(iter(w))
132132
return self._cache['ctrlpts']
133133

134134
@ctrlpts.setter
@@ -159,8 +159,8 @@ def weights(self):
159159
# Populate the cache, if necessary
160160
if not self._cache['weights']:
161161
c, w = compatibility.separate_ctrlpts_weights(self._control_points)
162-
self._cache['ctrlpts'] = [crd for crd in c]
163-
self._cache['weights'] = w
162+
self._cache['ctrlpts'] = self._array_type(iter(c))
163+
self._cache['weights'] = self._array_type(iter(w))
164164
return self._cache['weights']
165165

166166
@weights.setter
@@ -192,6 +192,7 @@ def reset(self, **kwargs):
192192
if reset_ctrlpts:
193193
# Delete the caches
194194
self._cache['ctrlpts'] = self._init_array()
195+
# TODO: why is this reset differently from the initialisation?
195196
self._cache['weights'][:] = self._init_array()
196197

197198

@@ -330,8 +331,8 @@ def ctrlpts(self):
330331
"""
331332
if not self._cache['ctrlpts']:
332333
c, w = compatibility.separate_ctrlpts_weights(self._control_points)
333-
self._cache['ctrlpts'] = [crd for crd in c]
334-
self._cache['weights'] = w
334+
self._cache['ctrlpts'] = self._array_type(iter(c))
335+
self._cache['weights'] = self._array_type(iter(w))
335336
return self._cache['ctrlpts']
336337

337338
@ctrlpts.setter
@@ -361,8 +362,8 @@ def weights(self):
361362
"""
362363
if not self._cache['weights']:
363364
c, w = compatibility.separate_ctrlpts_weights(self._control_points)
364-
self._cache['ctrlpts'] = [crd for crd in c]
365-
self._cache['weights'] = w
365+
self._cache['ctrlpts'] = self._array_type(iter(c))
366+
self._cache['weights'] = self._array_type(iter(w))
366367
return self._cache['weights']
367368

368369
@weights.setter
@@ -518,8 +519,8 @@ def ctrlpts(self):
518519
"""
519520
if not self._cache['ctrlpts']:
520521
c, w = compatibility.separate_ctrlpts_weights(self._control_points)
521-
self._cache['ctrlpts'] = [crd for crd in c]
522-
self._cache['weights'] = w
522+
self._cache['ctrlpts'] = self._array_type(iter(c))
523+
self._cache['weights'] = self._array_type(iter(w))
523524
return self._cache['ctrlpts']
524525

525526
@ctrlpts.setter
@@ -549,8 +550,8 @@ def weights(self):
549550
"""
550551
if not self._cache['weights']:
551552
c, w = compatibility.separate_ctrlpts_weights(self._control_points)
552-
self._cache['ctrlpts'] = [crd for crd in c]
553-
self._cache['weights'] = w
553+
self._cache['ctrlpts'] = self._array_type(iter(c))
554+
self._cache['weights'] = self._array_type(iter(w))
554555
return self._cache['weights']
555556

556557
@weights.setter

geomdl/abstract.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .six import add_metaclass
1212
from . import vis, helpers, knotvector, voxelize, utilities, tessellate
1313
from .base import GeomdlBase, GeomdlEvaluator, GeomdlError, GeomdlWarning, GeomdlTypeSequence
14+
from ._collections import NotifyList
1415

1516

1617
@add_metaclass(abc.ABCMeta)
@@ -34,9 +35,9 @@ class Geometry(GeomdlBase):
3435
# __slots__ = ('_iter_index', '_array_type', '_eval_points')
3536

3637
def __init__(self, *args, **kwargs):
37-
self._geometry_type = "default" if not hasattr(self, '_geometry_type') else self._geometry_type # geometry type
3838
super(Geometry, self).__init__(*args, **kwargs)
39-
self._array_type = list if not hasattr(self, '_array_type') else self._array_type # array storage type
39+
self._geometry_type = getattr(self, '_geometry_type', 'default') # geometry type
40+
self._array_type = getattr(self, '_array_type', NotifyList) # array storage type
4041
self._eval_points = self._init_array() # evaluated points
4142

4243
def __iter__(self):

0 commit comments

Comments
 (0)