@@ -91,9 +91,11 @@ def __deepcopy__(self, memo):
9191 result .init_cache ()
9292 return result
9393
94- def init_cache (self ):
95- self ._cache ['ctrlpts' ] = self ._init_array ()
96- self ._cache ['weights' ] = self ._init_array ()
94+ def init_cache (self , ctrlpts = [], weights = []):
95+ self ._cache ['ctrlpts' ] = self ._array_type (iter (ctrlpts ))
96+ self ._cache ['weights' ] = self ._array_type (iter (weights ))
97+ self ._cache ['ctrlpts' ].register_callback (lambda : setattr (self , '_control_points_valid' , False ))
98+ self ._cache ['weights' ].register_callback (lambda : setattr (self , '_control_points_valid' , False ))
9799
98100 @property
99101 def ctrlptsw (self ):
@@ -107,6 +109,9 @@ def ctrlptsw(self):
107109 :getter: Gets the weighted control points
108110 :setter: Sets the weighted control points
109111 """
112+ if not self ._control_points_valid :
113+ ctrlptsw = compatibility .combine_ctrlpts_weights (self .ctrlpts , self .weights )
114+ self .set_ctrlpts (ctrlptsw )
110115 return self ._control_points
111116
112117 @ctrlptsw .setter
@@ -127,22 +132,17 @@ def ctrlpts(self):
127132 # Populate the cache, if necessary
128133 if not self ._cache ['ctrlpts' ]:
129134 c , w = compatibility .separate_ctrlpts_weights (self ._control_points )
130- self ._cache ['ctrlpts' ] = self ._array_type (iter (c ))
131- self ._cache ['weights' ] = self ._array_type (iter (w ))
135+ self .init_cache (c , w )
132136 return self ._cache ['ctrlpts' ]
133137
134138 @ctrlpts .setter
135139 def ctrlpts (self , value ):
136140 # Check if we can retrieve the existing weights. If not, generate a weights vector of 1.0s.
137141 if not self .weights :
138- weights = [1.0 for _ in range (len (value ))]
139- else :
140- weights = self .weights
142+ self .weights [:] = [1.0 for _ in range (len (value ))]
141143
142144 # Generate weighted control points using the new control points
143- ctrlptsw = compatibility .combine_ctrlpts_weights (value , weights )
144-
145- # Set new weighted control points
145+ ctrlptsw = compatibility .combine_ctrlpts_weights (value , self .weights )
146146 self .set_ctrlpts (ctrlptsw )
147147
148148 @property
@@ -159,8 +159,7 @@ 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' ] = self ._array_type (iter (c ))
163- self ._cache ['weights' ] = self ._array_type (iter (w ))
162+ self .init_cache (c , w )
164163 return self ._cache ['weights' ]
165164
166165 @weights .setter
@@ -174,6 +173,12 @@ def weights(self, value):
174173 # Set new weighted control points
175174 self .set_ctrlpts (ctrlptsw )
176175
176+ def _check_variables (self ):
177+ super (Curve , self )._check_variables ()
178+ if not self ._control_points_valid :
179+ ctrlptsw = compatibility .combine_ctrlpts_weights (self .ctrlpts , self .weights )
180+ self .set_ctrlpts (ctrlptsw )
181+
177182 def reset (self , ** kwargs ):
178183 """ Resets control points and/or evaluated points.
179184
@@ -189,11 +194,9 @@ def reset(self, **kwargs):
189194 # Call parent function
190195 super (Curve , self ).reset (ctrlpts = reset_ctrlpts , evalpts = reset_evalpts )
191196
197+ # Delete the caches
192198 if reset_ctrlpts :
193- # Delete the caches
194- self ._cache ['ctrlpts' ] = self ._init_array ()
195- # TODO: why is this reset differently from the initialisation?
196- self ._cache ['weights' ][:] = self ._init_array ()
199+ self .init_cache ()
197200
198201
199202@export
0 commit comments