Skip to content

Commit

Permalink
now requires PHP >= 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jtejido committed Apr 28, 2018
1 parent e0c5ea8 commit 48471cb
Show file tree
Hide file tree
Showing 37 changed files with 149 additions and 118 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=7.0.0"
},
"autoload": {
"psr-4": {
Expand All @@ -23,6 +23,6 @@
}
},
"require-dev": {
"phpunit/phpunit": "5.*"
"phpunit/phpunit": "6.*"
}
}
3 changes: 2 additions & 1 deletion src/Geodesy/Conversion/ECEF2LLA.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function __construct(ECEF $ecef)
$this->datum = $this->ecef->getReference();
}

public function convert(){
public function convert(): LatLong
{

$x = $this->ecef->getX();
$y = $this->ecef->getY();
Expand Down
3 changes: 2 additions & 1 deletion src/Geodesy/Conversion/LLA2ECEF.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function __construct(LatLong $latlong)
$this->datum = $this->latlong->getReference();
}

public function convert(){
public function convert(): ECEF
{

$lat = deg2rad($this->latlong->getLatitude());

Expand Down
27 changes: 14 additions & 13 deletions src/Geodesy/Datum/BaseDatum.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,73 @@ public function __construct(ModelInterface $model)
}
}

public abstract function datum(): array;

public function getDatum()
public function getDatum(): array
{
return $this->datum();
}

public function getModel()
public function getModel(): ModelInterface
{
return $this->model;
}

public function getFlattening()
public function getFlattening(): float
{
return $this->getModel()->getFlattening();
}

public function getInverseFlattening()
public function getInverseFlattening(): float
{
return $this->getModel()->getInverseFlattening();
}

public function getSemiMajorAxis()
public function getSemiMajorAxis(): float
{
return $this->getModel()->getSemiMajorAxis();
}

public function getSemiMinorAxis()
public function getSemiMinorAxis(): float
{
return $this->getModel()->getSemiMinorAxis();
}

public function getFirstEccentricitySquared()
public function getFirstEccentricitySquared(): float
{
return $this->getModel()->getFirstEccentricitySquared();
}

public function getSecondEccentricitySquared()
public function getSecondEccentricitySquared(): float
{
return $this->getModel()->getSecondEccentricitySquared();
}

public function transform(ECEF $ecef)
public function transform(ECEF $ecef): ECEF
{

return $this->helmertTransform($ecef);
}

public function getScaleFactor()
public function getScaleFactor(): float
{

return $this->datum()['Scale'];
}

public function getTranslationalVectors()
public function getTranslationalVectors(): array
{

return $this->datum()['TranslationVectors'];
}

public function getRotationalVectors()
public function getRotationalVectors(): array
{

return $this->datum()['RotationalVectors'];
}

private function helmertTransform(ECEF $ecef)
private function helmertTransform(ECEF $ecef): ECEF
{

if($ecef->getReference() instanceof $this) {
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/DatumInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
interface DatumInterface
{


public function datum(): array;
}
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/ED50.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Intl1924);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/Irl1975.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new AiryModified);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/LuzonA.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Clarke1866);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/LuzonB.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Clarke1866);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/NAD27.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Clarke1866);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/NAD83.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new GRS80);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/NTF.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Clarke1880IGN);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/OSGB36.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Airy1830);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/PRS92.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new PRS92Model);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/Potsdam.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Bessel1841);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/TokyoJapan.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new Bessel1841);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/WGS72.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new WGS72Model);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Datum/WGS84.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct()
parent::__construct(new WGS84Model);
}

public function datum()
public function datum(): array
{
return array (
'TranslationVectors' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Distance/AndoyerLambert.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(LatLong $source, LatLong $destination)
}


public function distance()
public function distance(): float
{

$lat1 = $this->lat1;
Expand Down
14 changes: 7 additions & 7 deletions src/Geodesy/Distance/BaseDistance.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public function setUnit(UnitInterface $unit)
$this->unit = $unit;
}

public function getUnit()
public function getUnit(): UnitInterface
{
return $this->unit;
}

public function getDistance()
public function getDistance(): float
{
if($this->commonDatum !== null) {
return $this->getUnit()->convert($this->distance());
Expand All @@ -85,24 +85,24 @@ public function transformSource(DatumInterface $datum)

}

public function getSemiMajorAxis()
public function getSemiMajorAxis(): float
{
return $this->commonDatum->getSemiMajorAxis();
}

public function getSemiMinorAxis()
public function getSemiMinorAxis(): float
{
return $this->commonDatum->getSemiMinorAxis();
}

public function getInverseFlattening()
public function getInverseFlattening(): float
{
return $this->commonDatum->getInverseFlattening();
}

abstract public function distance();
abstract public function distance(): float;

public function isInRange($range)
public function isInRange(float $range)
{
return $this->getDistance() <= $this->getUnit()->convert($range);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Geodesy/Distance/DistanceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
interface DistanceInterface
{

public function distance();
public function distance(): float;

}
2 changes: 1 addition & 1 deletion src/Geodesy/Distance/HaversineFormula.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(LatLong $source, LatLong $destination)
* d = R * c
* where φ1 = lat1, φ2 = lat2, Δφ = (lat2-lat1), Δλ = (long2-long1), R = Earth's mean radius (in kilometers)
*/
public function distance()
public function distance(): float
{
$lat1 = $this->lat1;
$lat2 = $this->lat2;
Expand Down
13 changes: 4 additions & 9 deletions src/Geodesy/Distance/HubenyFormula.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(LatLong $source, LatLong $destination)
}


public function distance()
public function distance(): float
{
$lat1 = $this->lat1;
$lat2 = $this->lat2;
Expand All @@ -23,26 +23,21 @@ public function distance()
$a = $this->getSemiMajorAxis();
$b = $this->getSemiMinorAxis();
$f = $this->getInverseFlattening();
$f2 = ($b * $b) / ($a * $a);
$f2 = pow($b, 2) / pow($a, 2);
$e2 = 1.0 - $f2;

$lat_diff = ($lat1 - $lat2);
$long_diff = ($long1 - $long2);
$lat_average = 0.5 * ($lat1 + $lat2);
$sinlat_average = sin($lat_average);
$coslat_average = cos($lat_average);
$w2 = 1.0 - $sinlat_average * $sinlat_average * $e2;
$w2 = 1.0 - pow($sinlat_average, 2) * $e2;
$w = sqrt($w2);
$meridian = $a * $f2 / ($w2 * $w);
$n = $a / $w;

return sqrt(
$lat_diff * $lat_diff * $meridian * $meridian +
$long_diff * $long_diff * $n * $n * $coslat_average * $coslat_average
);
return sqrt(pow($lat_diff, 2) * pow($meridian, 2) + pow($long_diff, 2) * pow($n, 2) * pow($coslat_average, 2));


return $a*($spherical_distance+$delta);
}

}
4 changes: 2 additions & 2 deletions src/Geodesy/Distance/SphericalCosine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function __construct(LatLong $source, LatLong $destination)
* d = acos( sin φ1 * sin φ2 + cos φ1 * cos φ2 * cos Δλ ) * R
* where φ1 = lat1, φ2 = lat2, Δλ = (long2-long1), R = Earth's mean radius (in kilometers)
*/
public function distance()
public function distance(): float
{
$lat1 = $this->lat1;
$lat2 = $this->lat2;
$long1 = $this->long1;
$long2 = $this->long2;
$long_diff = $long2 - $long1;
return acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($long_diff)) * $this->constants::SPHERICAL_R;
return acos(pow(sin($lat1), 2) + pow(cos($lat1), 3) ) * $this->constants::SPHERICAL_R;
}

}
Loading

0 comments on commit 48471cb

Please sign in to comment.