Comments (7)
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.
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.
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.
I’ve reproduced this in a notebook: https://observablehq.com/d/cbcdfb87c58882b4. See the gap in cell 96.
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.
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.
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.
@Fil - Any idea when this fix will show up in the version at https://cdn.jsdelivr.net/npm/d3-delaunay@6 ?
from d3-delaunay.
@madcowfpb I just published it and it is live now. Thank you again for the bug report.
from d3-delaunay.
Related Issues (20)
- Generating higher-order Voronoi diagrams HOT 1
- Adding points incrementally without retriangulating HOT 3
- voronoi.cellPolygons skips null cells, and doesn’t report the cell’s index. HOT 3
- README misleading with "no-dependency library" line HOT 2
- Error with es6 worker + es6 modules HOT 18
- Would it be possible to make this work with a convex hull boundary for the Voronoi cells? HOT 2
- Delaunay points are a list of NaN HOT 1
- _edge() Comparison of numbers is unsafe HOT 5
- voronoi tiling goes a bit crazy when points are duplicated in the input HOT 1
- Broken voronoi HOT 3
- Update rollup and rollup-plugin-terser HOT 2
- Cosmetic Index out of bound check fix. HOT 1
- Minor change: Only compute bl and cl when needed. HOT 1
- renderPoints(5) crashes
- context.moveTo and context.lineTo implementation HOT 1
- Voronoi Polygon generator HOT 1
- convenience delaunay.edges() function?
- Edges that both sides are clipped sometimes will not be identified as voronoi neighbor HOT 2
- Odd failure HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-delaunay.