gorhill / Javascript-Voronoi

A Javascript implementation of Fortune's algorithm to compute Voronoi cells
http://www.raymondhill.net/voronoi/
Other
1.02k stars 166 forks source link

Tip: You can pass through extra data with your sites coords, that is then in cells sites output. #43

Open hayden-t opened 1 year ago

hayden-t commented 1 year ago

var sites = [ {x: 200, y: 200, specialValue: yes}]

and then that specialValueis now attached in the output of cells when the voronoi is calculated:

diagram.cells[i].site['specialValue']

Wuzzy2 commented 1 year ago

This is a bad idea to do it like this because you never know when the API changes and touches your custom value.

JavaScript offers symbols for that use case. https://javascript.info/symbol

Anyway, I think the documentation should mention that the cells sites contain references to your original sites objects, since this is useful to know. Otherwise, you might assumes the cells sites are just copies of those sites.