@@ -629,25 +629,24 @@ def setup(self, args):
629629 else : raise AttributeError (a + ' must be a vector' )
630630 del args [a ]
631631
632- vectorInteractions = [ ('size' ,'axis' ), ('axis' ,'size' ), ('axis' ,'up' ), ('up' ,'axis' )]
633-
634- # override defaults for vector attributes with side effects
632+ # Track side effects of modifying size, axis, or up
635633 # For consistency with GlowScript, axis is listed before up in the attrLists,
636634 # so that setting axis may affect up, but then setting up can affect axis afterwards.
637- attrs = standardAttributes .attrLists [objName ][1 ]
635+ attrs = standardAttributes .attrLists [objName ][1 ] # vector attributes with interactions
638636 for a in attrs :
639637 if a in args :
640638 val = args [a ]
641639 if isinstance (val , vector ):
642- setattr (self , a , vector (val )) ## use setter to take care of side effects; copy of val
640+ setattr (self , a , vector (val ))
643641 if a not in argsToSend :
644642 argsToSend .append (a )
645- for vi in vectorInteractions :
646- if vi [0 ] == a :
647- if vi [1 ] not in argsToSend :
648- argsToSend .append (vi [1 ])
649- elif objName == 'points' and a == 'size' : ## in this case size is a scalar
650- argsToSend .append (a )
643+ if a == 'size' :
644+ self ._axis = self ._axis .norm ()* val .x
645+ elif a == 'axis' :
646+ self ._size .x = mag (val )
647+ self .axis = val # this will have the side effect of modifying up
648+ elif a == 'up' :
649+ self .up = val # this will have the side effect of modifying axis
651650 else : raise AttributeError (a + ' must be a vector' )
652651 del args [a ]
653652
@@ -695,10 +694,8 @@ def setup(self, args):
695694 elif isinstance (aval , vertex ):
696695 aval = aval .idx
697696 if objName in nosize and a == 'size' : continue # do not send superfluous size
698- #cmd["attrs"].append({"attr":a, "value": aval})
699697 cmd [a ] = aval
700698
701-
702699 # set canvas
703700 if self .canvas is None : ## not specified in constructor
704701 self .canvas = canvas .get_selected ()
@@ -757,8 +754,6 @@ def up(self):
757754 def up (self ,value ):
758755 self ._save_oldup = adjust_axis (self ._up , value , self ._axis , self ._save_oldup ) # this sets self._axis and self._up
759756 if not self ._constructing :
760- # must update both axis and up when either is changed
761- self .addattr ('axis' )
762757 self .addattr ('up' )
763758
764759 @property
@@ -768,14 +763,8 @@ def axis(self):
768763 def axis (self ,value ):
769764 self ._save_oldaxis = adjust_up (self ._axis , value , self ._up , self ._save_oldaxis ) # this sets self._axis and self._up
770765 if not self ._constructing :
771- # must update both axis and up when either is changed
772766 self .addattr ('axis' )
773- self .addattr ('up' )
774- m = value .mag
775- if abs (self ._size ._x - m ) > 0.0001 * self ._size ._x : # need not update size if very small change
776- self ._size ._x = m
777- if not self ._constructing :
778- self .addattr ('size' )
767+ self ._size ._x = value .mag # changing axis length changes size.x
779768
780769 @property
781770 def size (self ):
@@ -788,11 +777,7 @@ def size(self,value):
788777 a = self ._axis .norm () * value .x
789778 if mag (self ._axis ) == 0 :
790779 a = vector (value .x ,0 ,0 )
791- v = self ._axis
792- if not v .equals (a ):
793- self ._axis .value = a
794- if not self ._constructing :
795- self .addattr ('axis' )
780+ self ._axis .value = a # changing size changes length of axis
796781
797782 @property
798783 def length (self ):
@@ -1263,37 +1248,6 @@ def __init__(self, **args):
12631248
12641249 super (arrow , self ).setup (args )
12651250
1266- @property
1267- def size (self ):
1268- return self ._size
1269- @size .setter
1270- def size (self ,value ): # no need to send to browser both arrow.size and arrow.axis
1271- self ._size .value = value
1272- if not self ._constructing :
1273- self .addattr ('size' )
1274- a = self ._axis .norm () * value .x
1275- if mag (self ._axis ) == 0 :
1276- a = vector (value .x ,0 ,0 )
1277- v = self ._axis
1278- if not v .equals (a ):
1279- self ._axis .value = a
1280-
1281- @property
1282- def axis (self ):
1283- return self ._axis
1284- @axis .setter
1285- def axis (self ,value ): # no need to send to browser both arrow.size and arrow.axis
1286- oldaxis = norm (self ._axis )
1287- self ._axis .value = value
1288- m = value .mag
1289- if abs (self ._size ._x - m ) > 0.0001 * self ._size ._x : # need not update size if very small change
1290- self ._size ._x = m
1291- self ._save_oldaxis = adjust_up (norm (oldaxis ), self ._axis , self ._up , self ._save_oldaxis )
1292- if not self ._constructing :
1293- # must update both axis and up when either is changed
1294- self .addattr ('axis' )
1295- self .addattr ('up' )
1296-
12971251 @property
12981252 def shaftwidth (self ):
12991253 return self ._shaftwidth
0 commit comments