GithubHelp home page GithubHelp logo

Odd failure about d3-delaunay HOT 4 CLOSED

madcowfpb avatar madcowfpb commented on April 28, 2024
Odd failure

from d3-delaunay.

Comments (4)

mbostock avatar mbostock commented on April 28, 2024

Here is a notebook to reproduce: https://observablehq.com/d/7624520d45e4b44f (In the future, if you’d be willing to share these reproductions as an Observable notebook, it would save us some time. Thank you!)

It renders fine when scaled and translated, as here with Plot:

untitled (32)

Plot.marks(Plot.voronoi(points), Plot.delaunayMesh(points)).plot()

But it looks like the there are some problems computing the Voronoi cell edges for points on the Delaunay hull.

image

from d3-delaunay.

Fil avatar Fil commented on April 28, 2024

Not that it helps much to understand why the bug happens, but this test case is correct under d3-delaunay@4.

from d3-delaunay.

Fil avatar Fil commented on April 28, 2024

In the collinear case (a "flat triangle" on the hull)

if (Math.abs(ab) < 1e-9) {
, we compute a to cast a long ray (1e9) towards the exterior in order to compute the circumcenter as the "point at infinity".

In this case a is sometimes 0, or going in the wrong direction, because the reference point r (point 36, marked as a green circle) happens to be exactly on the hull, and collinear with the (flat) triangle whose circumcenter we're trying to compute.

Capture d’écran 2023-03-25 à 10 01 57

So, any flat triangle on the collinear part of the hull has a 1/2 chance to have its (degenerate) circumcenter be projected in the wrong direction. This results in the weird polygonCell 180 (also in green).

A quick and dirty patch:

-        const r = triangles[0] * 2;
-        a *= Math.sign((points[r] - x1) * ey - (points[r + 1] - y1) * ex);
+        let i=0;
+        while (i < triangles.length && Math.abs(a) < 1e-3) {
+          const r = triangles[i++] * 2;
+          a =  ((points[r] - x1) * ey - (points[r + 1] - y1) * ex);
+        }
+        a = Math.sign(a) * 1e9;

There might be a better approach though, using the fact that the hull points are enumerated clockwise? Needs a bit more thought.

from d3-delaunay.

Fil avatar Fil commented on April 28, 2024

#142 fixes it, thanks for the test case!

from d3-delaunay.

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.