getkirby / geo

Geo Plugin for Kirby 3
https://getkirby.com
MIT License
18 stars 1 forks source link

NAN when giving two exact same points for distance calculation #2

Open seehat opened 2 years ago

seehat commented 2 years ago

The two points I tried to calculate the distance are completely the same and I get NAN as a result and expect 0:

object(Kirby\Geo\Point)#908 (2) { ["lat":protected]=> float(48.70064064733967512665913091041147708892822265625) ["lng":protected]=> float(16.803304953509563546276694978587329387664794921875) }

object(Kirby\Geo\Point)#908 (2) { ["lat":protected]=> float(48.70064064733967512665913091041147708892822265625) ["lng":protected]=> float(16.803304953509563546276694978587329387664794921875) }

The result of acos($dist) in Geo.php in the distance method becomes NAN, because $dist is greater than 1. I added a rounding to 14 decimal places with $dist = round($dist, 14);

Is there a cleaner way for this?

lukasbestle commented 2 years ago

I think this case of the same point can be hardcoded by checking if both lat and lng are the same. If so, return 0.