sroze / PHP-Voronoi-algorithm

Steven Fortune's algorithm in PHP
31 stars 15 forks source link

Lat Long #9

Open dmgctrlr opened 8 years ago

dmgctrlr commented 8 years ago

I'm trying to use this with map latitudes / longitudes.

Calling $voronoi->compute with 10 sites appears to hang.

My bbox is $bbox->xl = -113; $bbox->xr = -111; $bbox->yt = 31; $bbox->yb = 34;

but the Nurbs_Point x and y are floats, for example -111.972288 33.428495

Am I doing something wrong?

sroze commented 8 years ago

Hi @dmgctrlr! That's normal that points' coordinates are floats. However, it might be a bug if the x is slightly outside of the bbox...

Could you create a PR with a failing test? Or at least giving me a "failing" example?

dmgctrlr commented 8 years ago

Hi @sroze! thanks for your response. I'm not 100% sure that its failing, but even after 20 minutes it has not completed, whereas your example runs very fast. Here is an var_export of my $sites array is :

array ( 0 => Nurbs_Point::set_state(array( 'x' => '-112.121262', 'y' => '33.416515', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 1 => Nurbs_Point::set_state(array( 'x' => '-112.064830', 'y' => '33.419762', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 2 => Nurbs_Point::set_state(array( 'x' => '-112.050127', 'y' => '33.706717', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 3 => Nurbs_Point::set_state(array( 'x' => '-112.105545', 'y' => '33.688492', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 4 => Nurbs_Point::set_state(array( 'x' => '-111.945614', 'y' => '33.290901', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 5 => Nurbs_Point::set_state(array( 'x' => '-111.663908', 'y' => '33.342023', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 6 => Nurbs_Point::set_state(array( 'x' => '-111.993568', 'y' => '33.424774', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 7 => Nurbs_Point::set_state(array( 'x' => '-111.787722', 'y' => '33.504458', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), 8 => Nurbs_Point::__set_state(array( 'x' => '-111.857654', 'y' => '33.442678', 'z' => NULL, 'id' => NULL, 'halfedges' => array ( ), )), );

And my bbox is like this:

$bbox = new stdClass(); $bbox->xl = -114; $bbox->xr = -110; $bbox->yt = 31; $bbox->yb = 34;

When I then do

$voronoi = new Voronoi(); $diagram = $voronoi->compute( $sites, $bbox );

it does not complete. Am I misunderstanding something?

sroze commented 8 years ago

Erm, could you create a gist or something that I can run by copy/pasting to reproduce and hopeful fix the bug? Thanks :)

dmgctrlr commented 8 years ago

Is this suitable? Sorry I'm not very github savvy

https://gist.github.com/dmgctrlr/7dcf8b9f942c2f964546e78816480ef6

dmgctrlr commented 8 years ago

If it helps, when I use only the first 3 points in that array, it returns quite quickly. But if I extend that to the first 4 or 5 points, thats when it hangs.

sroze commented 5 years ago

Can you check again with master? This issue might have been the cause 🤔 https://github.com/sroze/PHP-Voronoi-algorithm/issues/13

chandon commented 5 years ago

Got the same problem with last master (including #13) Example with var_dump : array (size=5) 0 => object(sroze\voronoi\Nurbs\Point)[14130] public 'x' => string '50.793264' (length=9) public 'y' => string '4.310584' (length=8) public 'z' => null public 'id' => null public 'halfedges' => array (size=0) empty 1 => object(sroze\voronoi\Nurbs\Point)[14131] public 'x' => string '41.841491200825956' (length=18) public 'y' => string '12.552025384655735' (length=18) public 'z' => null public 'id' => null public 'halfedges' => array (size=0) empty 2 => object(sroze\voronoi\Nurbs\Point)[14132] public 'x' => string '41.90518551884903' (length=17) public 'y' => string '12.59976169311517' (length=17) public 'z' => null public 'id' => null public 'halfedges' => array (size=0) empty 3 => object(sroze\voronoi\Nurbs\Point)[14133] public 'x' => string '41.93228688638168' (length=17) public 'y' => string '12.594373965606678' (length=18) public 'z' => null public 'id' => null public 'halfedges' => array (size=0) empty 4 => object(sroze\voronoi\Nurbs\Point)[14134] public 'x' => string '48.2632233' (length=10) public 'y' => string '14.2610947' (length=10) public 'z' => null public 'id' => null public 'halfedges' => array (size=0) empty

chandon commented 5 years ago

This implementation is really not working, there should by a typo somewhere. Results are not consistants with 4 points...