Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Compare the following two code snippets :

Version 1

  pts = {{1, 1}, {0.2, 0.3}, {0.5, .3}}
  locpts = pts;
  Panel[
   LocatorPane[
    Dynamic[locpts,
     {(locpts = #; pts = #
        ) &}],
    Dynamic@
     Graphics[{Point[locpts], Dynamic[Polygon[locpts]]}, 
       PlotRange -> {{0, 1}, {0, 1}}],
    LocatorAutoCreate -> All]]

Version 2

  pts = {{1, 1}, {0.2, 0.3}, {0.5, .3}}
  locpts = pts;
  Panel[
   LocatorPane[
    Dynamic[locpts,
     {(locpts = #; pts = #
        ) &}],
        Dynamic@
     Graphics[{Point[locpts], Dynamic[Polygon[pts]]}, 
      PlotRange -> {{0, 1}, {0, 1}}],
    LocatorAutoCreate -> All]]

Both versions are the same except for the third line from below where Polygon[locpts] was changed to Polygon[pts].

In the first version a delete of a locator is immediately propagated in the graphic while this is not the case in the second version. I would expect no difference since I set both pts and locpts to #.

Question: what is the explanation of this behavior?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

It looks like the second argument of Dynamic in LocatorPane[Dynamic[locpts, ...], ...] isn't called when a locator is removed. Consider for example

pts = {{1, 1}, {0.2, 0.3}, {0.5, .3}}
locpts = pts;
Panel[
 LocatorPane[Dynamic[locpts, (Print[#]; locpts = #; pts = #) &], 
  Dynamic@Graphics[{Point[locpts], Polygon[pts]}, 
   PlotRange -> {{0, 1}, {0, 1}}, ImageSize -> 350],
  LocatorAutoCreate -> All]]

then the Print statement will only output a line when a locator is added or moved.

share|improve this answer
    
This snippet does not run, but I get your point. –  ndroock1 May 23 '12 at 14:59
    
broken code: brackets do not match –  Mr.Wizard May 23 '12 at 14:59
    
Yes, this is an accurate reflection of the question. Is this expected behavior? How can a removal of points best be trapped? –  ndroock1 May 23 '12 at 15:03
1  
@ndroock1 I've fixed the code now. –  Heike May 23 '12 at 15:08
    
Please see my previous comment ( if you haven't done so already. ) –  ndroock1 May 23 '12 at 15:17
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.