3

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?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
nilo de roock
  • 9,657
  • 3
  • 35
  • 77

1 Answers1

3

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.

Heike
  • 35,858
  • 3
  • 108
  • 157