GithubHelp home page GithubHelp logo

Comments (7)

madcowfpb avatar madcowfpb commented on April 28, 2024 1

Here's a version exhibiting the issue with 9 points. It makes no sense to me, but the issue does not seem to occur unless the input array of points is copied.

image

html source:

<style> body {padding: 0; margin: 0;} </style> <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script> <script src="https://cdn.jsdelivr.net/npm/d3-delaunay@6"></script> <script>

let delaunay;
let voronoi;
let npts = 0;
let npts1 = 0;
let pt1 = [];
let pt = [];

function setup() {

pixelDensity(1);

angleMode(DEGREES);
noLoop();

createCanvas(1200,900);

pt[npts++] = [447.27981036477433, 698.9400262172304];
pt[npts++] = [485.27830313288746, 668.9946483670656];
pt[npts++] = [611.9525697080425, 397.71056371206487];
pt[npts++] = [491.44637766366105, 692.071157339428];
pt[npts++] = [697.553622336339, 692.071157339428];
pt[npts++] = [497.00778156318086, 667.1990851383492];
pt[npts++] = [691.9922184368191, 667.1990851383492];
pt[npts++] = [544.9897579870977, 407.0828550310619];
pt[npts++] = [543.1738215956482, 437.35879519252677];

npts1 = 0
for (i=0; i<npts; i++) {
pt1[npts1++] = pt[i];
}
delaunay = d3.Delaunay.from(pt1);
voronoi = delaunay.voronoi([440, 380, 740, 850]);

}

function draw() {
noLoop();
console.log(pt1);
fill(255,0,0);

for (i=0; i<npts1; i++) {
point(pt1[i][0],pt1[i][1]);
let polygon = voronoi.cellPolygon(i);
if (polygon != null) {
console.log(polygon);
beginShape();
for (j=0; j<polygon.length; j++) {
vertex(polygon[j][0],polygon[j][1]);
}
endShape(CLOSE);
}
}
fill(0);
for (i=0; i<npts; i++) {
text(i,pt[i][0],pt[i][1]);
}
}
</script>

from d3-delaunay.

Fil avatar Fil commented on April 28, 2024 1

Thanks! I traced the problem to the code that we introduced for #88 in order to simplify the polygons when three consecutive points are aligned.

See #140 for a fix, build at https://observablehq.com/@d3/voronoi-issue-136

from d3-delaunay.

mbostock avatar mbostock commented on April 28, 2024

I’ve reproduced this in a notebook: https://observablehq.com/d/cbcdfb87c58882b4. See the gap in cell 96.

untitled (7)

I suspect that this is a numerical precision problem with the finite clipping implementation, and given that this library doesn’t use robust predicates (other than to compute the Delaunay triangulation thanks to the underlying delaunator library), I’m not sure it’s readily fixable. But maybe there’s a way.

from d3-delaunay.

Fil avatar Fil commented on April 28, 2024

Slightly tweaking the coordinates fixes the notebook:

    Plot.voronoi(delaunay136, {
      x: (d,i) => d[0] + i * 1e-13,
      y: (d) => d[1],

Fixing the bug is another matter; the fun part is that it happens at the bottom of the screen, but it is not triggered if you remove the points at the top with delaunay136.filter(d => d[1] > 183).

from d3-delaunay.

madcowfpb avatar madcowfpb commented on April 28, 2024

Walking through the execution of this, it looks like there's a bug in the clipping implementation. The circumcenters for the botched cell are correctly computed and passed to _clipfinite. The first two circumcenters are in the region (these are coincidentally the same, and are the top right point of the botched cell). The third is out of (below) the region and this segment is correctly clipped at the bottom of the enclosing rectangle. The problem arises when dealing with the fourth circumcenter which is back in the region. I don't understand exactly where the bug is, but instead of adding a segment along the edge and another clipped segment to the fourth circumcenter what happens is the array holding the clipped version is reinitialized and ends up containing only the clipped segment from the third circumcenter to the fourth.

from d3-delaunay.

madcowfpb avatar madcowfpb commented on April 28, 2024

@Fil - Any idea when this fix will show up in the version at https://cdn.jsdelivr.net/npm/d3-delaunay@6 ?

from d3-delaunay.

mbostock avatar mbostock commented on April 28, 2024

@madcowfpb I just published it and it is live now. Thank you again for the bug report.

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.