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

Exception “The distance must be greater than zero!” when providing same coords twice #3

Closed
alexislefebvre opened this issue Sep 23, 2022 · 1 comment

Comments

@alexislefebvre
Copy link

alexislefebvre commented Sep 23, 2022

Hello and thanks for the library.

I get an error when I try to calculate the distance between 2 points that have same coordinates.

I think it should check with !$distance >= 0 instead of !$distance > 0 here:

if (!$distance > 0) {
throw new \InvalidArgumentException('The distance must be greater than zero!');
}

A distance of 0 is valid in my humble opinion.

One (untested) example:

$centralIpswich = new LatLong(51.73441738801072, 0.4632282257080078); // Central Ipswich co-ordinates!
$centralAylesbury = new LatLong(51.73441738801072, 0.4632282257080078); // Central Ipswich co-ordinates!

// Create a new instance of the class passing in two coordinates (LatLong objects)
$pointToPointCalculator = new Calculator($centralIpswich, $centralAylesbury);

// Calculate the distance and return in both kilometre and miles...
$km = $pointToPointCalculator->get()->asKilometres();
@allebb
Copy link
Owner

allebb commented Nov 8, 2023

This has now been implement in PR: #4

@allebb allebb closed this as completed Nov 8, 2023
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