3
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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