-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
I'm trying to compute with 3 points, i got incoherent result (with empty area and overlaping areas...)
I tried it with gorhill/Javascript-Voronoi, the result is OK
I tried to compare gorhill/Javascript-Voronoi vs this library (and implemented some fixes, like fully rewriting closeCells), but i don't see any real difference between the 2 libraries that explain the problem
$voronoi=new \sroze\voronoi\Nurbs\Voronoi();
$bbox = new \stdClass();
$bbox->xl = 0;
$bbox->xr = 360;
$bbox->yt = 0;
$bbox->yb = 360;
$sitesList=[
new \sroze\voronoi\Nurbs\Point(230.8672211,94.3521468),
new \sroze\voronoi\Nurbs\Point(230.793264,94.310584),
new \sroze\voronoi\Nurbs\Point(221.84149120083,102.55202538466)
];
$diagram = $voronoi->compute($sitesList, $bbox);
// TEMPORARY
// Create image using GD
$im = imagecreatetruecolor(360, 360);
// Create colors
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 100, 0);
$black = imagecolorallocate($im, 0, 0, 0);
// Fill white background
imagefill($im, 0, 0, $white);
// Draw points
for ($i=0; $i < count($sitesList); $i++) {
$point = $sitesList[$i];
imagerectangle($im, $point->x - 2, $point->y - 2, $point->x + 2, $point->y + 2, $black);
}
// Draw polygons
$j = 0;
foreach ($diagram['cells'] as $cell) {
{
$points = array();
if (count($cell->_halfedges) > 0) {
$v = $cell->_halfedges[0]->getStartPoint();
if ($v) {
$points[] = $v->x;
$points[] = $v->y;
} else {
var_dump($j.': no start point');
}
for ($i = 0; $i < count($cell->_halfedges); $i++) {
$halfedge = $cell->_halfedges[$i];
$edge = $halfedge->edge;
if ($edge->va && $edge->vb) {
imageline($im, $edge->va->x, $edge->va->y, $edge->vb->x, $edge->vb->y, $red);
}
$v = $halfedge->getEndPoint();
if ($v) {
$points[] = $v->x;
$points[] = $v->y;
}
}
}
// Create polygon with a random color
$color = imagecolorallocatealpha($im, rand(0, 255), rand(0, 255), rand(0, 255), 50);
imagefilledpolygon($im, $points, count($points) / 2, $color);
}
$j++;
}
// Display image
header('Content-Type: image/png');
imagepng($im);
die;
Metadata
Metadata
Assignees
Labels
No labels