Bug in Voronoi built-in?
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:
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
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)
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
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:
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
Try using the syntax
https://wiki.geogebra.org/e...
to add an object to an existing list which will be more robust than rebuilding the list each time.
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.
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
.substr is the command I was searching. Thanks
I would add a removeundefined[] to list for preverting deleted or dependent points.
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 have been locked on this page!