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

Cleanup/small fixes #50

Merged
merged 5 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions src/Bearing/BearingEllipsoidal.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
<?php
declare(strict_types=1);

/**
* Calculation of bearing between two points using a
* ellipsoidal model of the earth
*
* This class is based on the awesome work Chris Veness
* has done. For more information visit the following URL.
*
* @see http://www.movable-type.co.uk/scripts/latlong-vincenty.html
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location\Bearing;

use InvalidArgumentException;
use Location\Coordinate;
use Location\Exception\NotConvergingException;

/**
* Calculation of bearing between two points using a
* ellipsoidal model of the earth
* ellipsoidal model of the earth.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* This class is based on the awesome work Chris Veness
* has done. For more information visit the following URL.
*
* @see http://www.movable-type.co.uk/scripts/latlong-vincenty.html
*
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class BearingEllipsoidal implements BearingInterface
{
/**
* This method calculates the initial bearing between the
* two points.
*
* @param \Location\Coordinate $point1
* @param \Location\Coordinate $point2
* @param Coordinate $point1
* @param Coordinate $point2
*
* @return float Bearing Angle
*/
Expand All @@ -47,8 +37,8 @@ public function calculateBearing(Coordinate $point1, Coordinate $point2): float
/**
* Calculates the final bearing between the two points.
*
* @param \Location\Coordinate $point1
* @param \Location\Coordinate $point2
* @param Coordinate $point1
* @param Coordinate $point2
*
* @return float
*/
Expand All @@ -61,7 +51,7 @@ public function calculateFinalBearing(Coordinate $point1, Coordinate $point2): f
* Calculates a destination point for the given point, bearing angle,
* and distance.
*
* @param \Location\Coordinate $point
* @param Coordinate $point
* @param float $bearing the bearing angle between 0 and 360 degrees
* @param float $distance the distance to the destination point in meters
*
Expand All @@ -77,13 +67,13 @@ public function calculateDestination(Coordinate $point, float $bearing, float $d
* The method expects a starting point point, the bearing angle,
* and the distance to destination.
*
* @param \Location\Coordinate $point
* @param Coordinate $point
* @param float $bearing
* @param float $distance
*
* @return float
*
* @throws \Location\Exception\NotConvergingException
* @throws NotConvergingException
*/
public function calculateDestinationFinalBearing(Coordinate $point, float $bearing, float $distance): float
{
Expand All @@ -97,8 +87,8 @@ public function calculateDestinationFinalBearing(Coordinate $point, float $beari
*
* @return DirectVincentyBearing
*
* @throws \Location\Exception\NotConvergingException
* @throws \InvalidArgumentException
* @throws NotConvergingException
* @throws InvalidArgumentException
*/
private function directVincenty(Coordinate $point, float $bearing, float $distance): DirectVincentyBearing
{
Expand Down Expand Up @@ -162,7 +152,7 @@ private function directVincenty(Coordinate $point, float $bearing, float $distan
*
* @return InverseVincentyBearing
*
* @throws \Location\Exception\NotConvergingException
* @throws NotConvergingException
*/
private function inverseVincenty(Coordinate $point1, Coordinate $point2): InverseVincentyBearing
{
Expand Down
15 changes: 10 additions & 5 deletions src/Bearing/BearingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

use Location\Coordinate;

/**
* Interface BearingInterface
*
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
interface BearingInterface
{
/**
* This method calculates the initial bearing between the
* two points.
*
* @param \Location\Coordinate $point1
* @param \Location\Coordinate $point2
* @param Coordinate $point1
* @param Coordinate $point2
*
* @return float Bearing Angle
*/
Expand All @@ -21,8 +26,8 @@ public function calculateBearing(Coordinate $point1, Coordinate $point2): float;
/**
* Calculates the final bearing between the two points.
*
* @param \Location\Coordinate $point1
* @param \Location\Coordinate $point2
* @param Coordinate $point1
* @param Coordinate $point2
*
* @return float
*/
Expand All @@ -32,7 +37,7 @@ public function calculateFinalBearing(Coordinate $point1, Coordinate $point2): f
* Calculates a destination point for the given point, bearing angle,
* and distance.
*
* @param \Location\Coordinate $point
* @param Coordinate $point
* @param float $bearing the bearing angle between 0 and 360 degrees
* @param float $distance the distance to the destination point in meters
*
Expand Down
26 changes: 8 additions & 18 deletions src/Bearing/BearingSpherical.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
<?php
declare(strict_types=1);

/**
* Calculation of bearing between two points using a
* simple spherical model of the earth.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location\Bearing;

use InvalidArgumentException;
use Location\Coordinate;

/**
* Calculation of bearing between two points using a
* simple spherical model of the earth.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class BearingSpherical implements BearingInterface
{
Expand All @@ -33,8 +23,8 @@ class BearingSpherical implements BearingInterface
* This method calculates the initial bearing between the
* two points.
*
* @param \Location\Coordinate $point1
* @param \Location\Coordinate $point2
* @param Coordinate $point1
* @param Coordinate $point2
*
* @return float Bearing Angle
*/
Expand All @@ -60,8 +50,8 @@ public function calculateBearing(Coordinate $point1, Coordinate $point2): float
/**
* Calculates the final bearing between the two points.
*
* @param \Location\Coordinate $point1
* @param \Location\Coordinate $point2
* @param Coordinate $point1
* @param Coordinate $point2
*
* @return float
*/
Expand All @@ -76,12 +66,12 @@ public function calculateFinalBearing(Coordinate $point1, Coordinate $point2): f
* Calculates a destination point for the given point, bearing angle,
* and distance.
*
* @param \Location\Coordinate $point
* @param Coordinate $point
* @param float $bearing the bearing angle between 0 and 360 degrees
* @param float $distance the distance to the destination point in meters
*
* @return Coordinate
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function calculateDestination(Coordinate $point, float $bearing, float $distance): Coordinate
{
Expand Down
12 changes: 1 addition & 11 deletions src/Bearing/DirectVincentyBearing.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
<?php
declare(strict_types=1);

/**
* Value object for a "Direct Vincenty" bearing calculation result.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location\Bearing;

use Location\Coordinate;

/**
* Value object for a "Direct Vincenty" bearing calculation result.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class DirectVincentyBearing
{
Expand Down
12 changes: 1 addition & 11 deletions src/Bearing/InverseVincentyBearing.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
<?php
declare(strict_types=1);

/**
* Value object for a "Inverse Vincenty" bearing calculation result.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location\Bearing;

/**
* Value object for a "Direct Vincenty" bearing calculation result.
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class InverseVincentyBearing
{
Expand Down
4 changes: 1 addition & 3 deletions src/Bounds.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
/**
* Coordinate Bounds Class
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class Bounds
{
Expand Down
24 changes: 5 additions & 19 deletions src/Coordinate.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?php
declare(strict_types=1);

/**
* Coordinate Implementation
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location;

use Location\Distance\DistanceInterface;
Expand All @@ -17,9 +9,7 @@
/**
* Coordinate Implementation
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class Coordinate implements GeometryInterface
{
Expand Down Expand Up @@ -55,10 +45,10 @@ public function __construct(float $lat, float $lng, Ellipsoid $ellipsoid = null)
throw new \InvalidArgumentException("Longitude value must be numeric -180.0 .. +180.0 (given: {$lng})");
}

$this->lat = (float)$lat;
$this->lng = (float)$lng;
$this->lat = $lat;
$this->lng = $lng;

if ($ellipsoid !== null) {
if ($ellipsoid instanceof Ellipsoid) {
$this->ellipsoid = $ellipsoid;

return;
Expand Down Expand Up @@ -161,10 +151,6 @@ protected function isValidLongitude(float $longitude): bool
*/
protected function isNumericInBounds(float $value, float $lower, float $upper): bool
{
if ($value < $lower || $value > $upper) {
return false;
}

return true;
return !($value < $lower || $value > $upper);
}
}
12 changes: 1 addition & 11 deletions src/Distance/DistanceInterface.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
<?php
declare(strict_types=1);

/**
* Interface for Distance Calculator Classes
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location\Distance;

use Location\Coordinate;

/**
* Interface for Distance Calculator Classes
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
interface DistanceInterface
{
Expand Down
16 changes: 3 additions & 13 deletions src/Distance/Haversine.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?php
declare(strict_types=1);

/**
* Implementation of distance calculation with http://en.wikipedia.org/wiki/Law_of_haversines
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
*/

namespace Location\Distance;

use Location\Coordinate;
Expand All @@ -18,11 +10,9 @@
/**
* Implementation of distance calculation with http://en.wikipedia.org/wiki/Law_of_haversines
*
* @see http://en.wikipedia.org/wiki/Law_of_haversines
* @see http://en.wikipedia.org/wiki/Law_of_haversines
*
* @author Marcus Jaschen <mjaschen@gmail.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/mjaschen/phpgeo
* @author Marcus Jaschen <mjaschen@gmail.com>
*/
class Haversine implements DistanceInterface
{
Expand All @@ -36,7 +26,7 @@ class Haversine implements DistanceInterface
*/
public function getDistance(Coordinate $point1, Coordinate $point2): float
{
if ($point1->getEllipsoid() != $point2->getEllipsoid()) {
if ($point1->getEllipsoid()->getName() !== $point2->getEllipsoid()->getName()) {
throw new NotMatchingEllipsoidException('The ellipsoids for both coordinates must match');
}

Expand Down
Loading