Bug in Voronoi built-in?

fredekr shared this question 5 years ago
Answered

Hello,


I am trying to create a simple app where any point a student adds will automatically be added to a list of sites and the resulting Voronoi diagram will be constructed. The Voronoi diagram should be dynamically updated if sites are moved.


To do this, the best way I could find (is there a better way?) is to create some global JavaScript that and a listener. Whne a object of type point is added, the Javascipt then iterates through all object to build a list a points, then calls the Voronoi() built-in to create the Voronoi diagram.


This all seems to work, except that the Voronoi() function throws an illegal multiplication error like so:

1c6516e5e221c8c8fd43eca7f9de130d


Can anyone figure out what is happening? I have tried in Geogebra Classic and the Chrome app. I would love to see a more elegant implementation.


(On a side note: after any global JavaSript error, the file needs to be closed an re-loaded before any global JavaSript will run again. Is this intentional? Is there a way around this?)


I"ve attached the ggb file ... help!


Many thanks,

Kevin

Best Answer
photo

Another possibility (include delete and handling asynchrone listeners)

in your file asynchrone-listeners is the problem (in context voronoi =......, what is a delete and create)

Comments (8)

photo
1

I can not find the bug on your code

It is too long for my mind

I try shorter code ever

then I attach my file. create four or more points for testing

saludos

photo
1

Hello mathmagic,


Thanks for the response!


Your suggestion is not all the functionality I want. After a point is added, the user should be able to move existing points and the Voronoi should be updated. But because of the way that Geogebra handles lists (or objects in general), your code creates a copy of the list every time a new point is added, so if the original points are added the diagram is not updated.


Here's a picture:

e05497cf6197583fc677f083c9f8ba06

The green points are the copies created when added to the list. The labelled points (A, B, C, D, E) are the originals, and they can be moved but the Voronoi is not updated. :-(


I had the exact same problem which is why I had to make the long JavaScript version. Can you find a way to fix this problem?


Best,

Kevin

photo
1

Try using the syntax

  1. SetValue[list, Length[list+1], newPoint]


https://wiki.geogebra.org/e...


to add an object to an existing list which will be more robust than rebuilding the list each time.

photo
2

This is the syntax I use. But this syntax is for free list and the newPoint is not added to list, it is added the value of the point then the list is not updated when the point is moved.

I will solve this problem during this day if I have time to spend.

photo
1

Thanks for the responses, Michael and mathmagic.


Michael, I definitely want to avoid rebuilding the list each time but the problem with SetValue is that it adds the value of the point to the list, not the point object. So, when then original point is moved, the list is not updated because the previous value of the point was added, not the point object.


mathmagic, I look forward to your solution! I think there is a bug in Voronoi(), but perhaps a method different than mine can avoid it.


Thanks,

Kevin

photo
2

.substr is the command I was searching. Thanks

I would add a removeundefined[] to list for preverting deleted or dependent points.

photo
3

Another possibility (include delete and handling asynchrone listeners)

in your file asynchrone-listeners is the problem (in context voronoi =......, what is a delete and create)

photo
1

Rami,


This is brilliant. Not only did you handle deletion but you identified the problem in the original code was due to the asynchronous execution of the listeners. Fantastic!


Many thanks,

Kevin

photo
© 2022 International GeoGebra Institute