Giter Club home page Giter Club logo

Comments (5)

Fil avatar Fil commented on May 14, 2024 2

I have just added a few blocks to demonstrate what I'm trying to achieve:

Compute a voronoi spanning tree

Compute a better spanning tree

Traverse it

from d3-voronoi.

mbostock avatar mbostock commented on May 14, 2024

Neat!

from d3-voronoi.

Fil avatar Fil commented on May 14, 2024

Another application: Voronoi binning

from d3-voronoi.

mbostock avatar mbostock commented on May 14, 2024

I found a small bug in your optimization. Instead of this:

next = diagram.find.found || Math.floor(Math.random() * diagram.cells.length);

You want to say this:

next = diagram.find.found == null ? Math.floor(Math.random() * diagram.cells.length) : diagram.find.found;

Because sometimes the last-found index can be zero, and you want to treat that differently from it being undefined. Example here: http://bl.ocks.org/mbostock/76d0346147b55a08b91dcccf8da58291

Also, I think diagram._found would be a better place to stash the last-found index than putting it on the diagram.find method, especially since if this is implemented on Diagram.prototype the find function would be shared by all diagram instances.

Do you want to open a pull request to add this feature? Or do you want me to implement your suggested algorithm and add tests?

from d3-voronoi.

Fil avatar Fil commented on May 14, 2024

sometimes the last-found index can be zero, and you want to treat that
differently from it being undefined. Example here:
http://bl.ocks.org/mbostock/76d0346147b55a08b91dcccf8da58291

Math.random() is useless here — I put it because I tend to like it better
when things are evenly distributed, and to highlight that any starting
point will work. The only thing is to start with an existing site. On this
issue, I wonder if at some point the site with index 0 might disappear, for
example when we find a way to constructively add and remove sites from the
Diagram. Then we'll need to pop one site from the list.

In the meantime, I think diagram.find.found || 0 is more than enough.

Also, I think diagram._found would be a better place to stash the
last-found index than putting it on the diagram.find method, especially
since if this is implemented on Diagram.prototype
https://github.com/d3/d3-voronoi/blob/master/src/Diagram.js the find
function would be shared by all diagram instances.

right

Do you want to open a pull request to add this feature? Or do you want me
to implement your suggested algorithm and add tests?

Will start a PR.

-- Fil

from d3-voronoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.