@@ -91,9 +91,11 @@ def __deepcopy__(self, memo):
91
91
result .init_cache ()
92
92
return result
93
93
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 ))
97
99
98
100
@property
99
101
def ctrlptsw (self ):
@@ -107,6 +109,9 @@ def ctrlptsw(self):
107
109
:getter: Gets the weighted control points
108
110
:setter: Sets the weighted control points
109
111
"""
112
+ if not self ._control_points_valid :
113
+ ctrlptsw = compatibility .combine_ctrlpts_weights (self .ctrlpts , self .weights )
114
+ self .set_ctrlpts (ctrlptsw )
110
115
return self ._control_points
111
116
112
117
@ctrlptsw .setter
@@ -127,22 +132,17 @@ def ctrlpts(self):
127
132
# Populate the cache, if necessary
128
133
if not self ._cache ['ctrlpts' ]:
129
134
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 )
132
136
return self ._cache ['ctrlpts' ]
133
137
134
138
@ctrlpts .setter
135
139
def ctrlpts (self , value ):
136
140
# Check if we can retrieve the existing weights. If not, generate a weights vector of 1.0s.
137
141
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 ))]
141
143
142
144
# 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 )
146
146
self .set_ctrlpts (ctrlptsw )
147
147
148
148
@property
@@ -159,8 +159,7 @@ def weights(self):
159
159
# Populate the cache, if necessary
160
160
if not self ._cache ['weights' ]:
161
161
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 )
164
163
return self ._cache ['weights' ]
165
164
166
165
@weights .setter
@@ -174,6 +173,12 @@ def weights(self, value):
174
173
# Set new weighted control points
175
174
self .set_ctrlpts (ctrlptsw )
176
175
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
+
177
182
def reset (self , ** kwargs ):
178
183
""" Resets control points and/or evaluated points.
179
184
@@ -189,11 +194,9 @@ def reset(self, **kwargs):
189
194
# Call parent function
190
195
super (Curve , self ).reset (ctrlpts = reset_ctrlpts , evalpts = reset_evalpts )
191
196
197
+ # Delete the caches
192
198
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 ()
197
200
198
201
199
202
@export
0 commit comments