power-voronoi-diagram
power-voronoi-diagram copied to clipboard
Wrong result for simple?
import kn.uni.voronoitreemap.datastructure.OpenList; import kn.uni.voronoitreemap.diagram.PowerDiagram; import kn.uni.voronoitreemap.j2d.PolygonSimple; import kn.uni.voronoitreemap.j2d.Site;
public class Diagrams { public static void main(String[] args) { // create a root polygon which limits the voronoi diagram // here it's just rectangle PolygonSimple rootPolygon = new PolygonSimple(); int width = 800; int height = 800; rootPolygon.add(0, 0); rootPolygon.add(width, 0); rootPolygon.add(width, height); rootPolygon.add(0, height);
OpenList sites = new OpenList();
// add test points
sites.add(new Site(400,200));
sites.add(new Site(200,400));
sites.add(new Site(400,400));
sites.add(new Site(600,400));
sites.add(new Site(400,600));
PowerDiagram diagram = new PowerDiagram();
diagram.setSites(sites);
diagram.setClipPoly(rootPolygon);
diagram.computeDiagram();
PolygonSimple p;
Site s;
for (int i = 0; i < sites.size; i++) {
s = sites.get(i);
p = s.getPolygon();
System.out.println("i: " + i + " " + s.getPoint() + " " + p.getNumPoints());
for (int j = 0; j < p.getNumPoints(); j++)
System.out.println("j: " + j + " x:" + p.getXPoints()[j] + " y:" + p.getYPoints()[j]);
System.out.println();
}
}
}
Output:
i: 0 (200.0,400.0) 4 j: 0 x:0.0 y:799.9999999999999 j: 1 x:0.0 y:0.0 j: 2 x:299.9999999999999 y:299.9999999999999 j: 3 x:299.99999999999983 y:499.9999999999999
i: 1 (400.0,400.0) 4 j: 0 x:299.9999999999999 y:299.9999999999999 j: 1 x:500.00000000000017 y:299.9999999999999 j: 2 x:500.0 y:499.9999999999999 j: 3 x:299.99999999999983 y:499.9999999999999
i: 2 (400.0,600.0) 7 j: 0 x:0.0 y:799.9999999999999 j: 1 x:299.99999999999983 y:499.9999999999999 j: 2 x:500.0 y:499.9999999999999 j: 3 x:800.0 y:799.9999999999999 j: 4 x:1045.4545454545455 y:1045.4545454545455 j: 5 x:400.0 y:1820.0 j: 6 x:-245.45454545454547 y:1045.4545454545455
i: 3 (600.0,400.0) 4 j: 0 x:800.0 y:800.0 j: 1 x:500.0 y:499.9999999999999 j: 2 x:500.00000000000017 y:299.9999999999999 j: 3 x:800.0 y:0.0
i: 4 (400.0,200.0) 4 j: 0 x:0.0 y:1.1368683772161603E-13 j: 1 x:800.0 y:0.0 j: 2 x:500.00000000000017 y:299.9999999999999
j: 3 x:299.9999999999999 y:299.9999999999999
Does this result is correct? ( x:1045.4545454545455 y:1045.4545454545455)? Why order of items at OpenList was changed? When rootPolygon is rootPolygon 1000*1000 - all work correctly.
I also noticed that reordering of sites is done and i cant tell why.
What worked for me, however, was to comment out line 120 in https://github.com/ArlindNocaj/power-voronoi-diagram/blob/master/src/kn/uni/voronoitreemap/diagram/PowerDiagram.java
=> sites will keep their correct order