Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voronoi Result missing an edge? #16

Closed
oderby opened this issue Dec 2, 2013 · 3 comments
Closed

Voronoi Result missing an edge? #16

oderby opened this issue Dec 2, 2013 · 3 comments

Comments

@oderby
Copy link

oderby commented Dec 2, 2013

Not sure if this is a bug or just an undocumented change, but I'm seeing the returned diagram missing the 4th edge for the middle cell in the following example using the latest version of the lib. Using an older version (can start digging to find out exactly which, but I'm guessing it was aad4ca6 as that was just before I started using the lib) did not have this problem.

var sites = [{x:2, y:5}, {x:5, y:5},{x:8, y:5}],
    bbox = {xl:0, xr:10, yt:0, yb:10};
var voronoi = new Voronoi();
var diagram = voronoi.compute(sites, bbox);
var polyBoundaries = diagram.cells.map(function(cell) {
    return cell.halfedges.map(function(edge) {
        return edge.getStartpoint();
    });
});
console.log(polyBoundaries);

which prints

[
    [
        {"x": 3.5, "y": 10},
        {"x": 3.5, "y": 0},
        {"x": 0, "y": 0},
        {"x": 0, "y": 10}
    ],
    [
        {"x": 3.5, "y": 0},
        {"x": 3.5, "y": 10},
        {"x": 6.5, "y": 10}
    ],
    [
        {"x": 6.5, "y": 0},
        {"x": 6.5, "y": 10},
        {"x": 10, "y": 10},
        {"x": 10, "y": 0}
    ]
]

The output I expect is

[
    [
        {"x": 0, "y": 0},
        {"x": 0, "y": 10},
        {"x": 3.5, "y": 10},
        {"x": 3.5, "y": 0}
    ],
    [
        {"x": 3.5, "y": 0},
        {"x": 3.5, "y": 10},
        {"x": 6.5, "y": 10},
        {"x": 6.5, "y": 0}
    ],
    [
        {"x": 6.5, "y": 0},
        {"x": 6.5, "y": 10},
        {"x": 10, "y": 10},
        {"x": 10, "y": 0}
    ]
]

If I should be using a different method to extract the points defining the boundary of the cells, let me know.

Note that adding another call to this.closeCells(bbox) at line 1687 properly adds the 4th edge, so I presume some corner case just got created or overlooked in a recent commit.

@gorhill
Copy link
Owner

gorhill commented Dec 2, 2013

You're right, in my fix to avoid infinite loop, I overlooked a possible last segment when walking along the bounding box, in the cases where a side of the bounding box has to be walked twice (at most), while my fix assumed it could be walked at most only once. Thanks for reporting.

@gorhill
Copy link
Owner

gorhill commented Dec 2, 2013

Nah, I have to revise my erroneous conclusion: I see it happening now with #15 fixed. Problem is bad assumption in the code: when closing a cell, the missing edges are not necessarily adjacent, which is what the code is currently assuming.

@gorhill
Copy link
Owner

gorhill commented Dec 2, 2013

Fixed with 95bfbd5

@gorhill gorhill closed this as completed Dec 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants