Skip to content
Open
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
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,18 @@ the *middle point* and the *destination point*. The middle and the destination p
$geotools = new \League\Geotools\Geotools();
$coordA = new \League\Geotools\Coordinate\Coordinate([48.8234055, 2.3072664]);
$coordB = new \League\Geotools\Coordinate\Coordinate([43.296482, 5.36978]);
$vertex = $geotools->vertex()->setFrom($coordA)->setTo($coordB);
$edge = $geotools->edge()->setFrom($coordA)->setTo($coordB);

printf("%d\n", $vertex->initialBearing()); // 157 (degrees)
printf("%s\n", $vertex->initialCardinal()); // SSE (SouthSouthEast)
printf("%d\n", $vertex->finalBearing()); // 160 (degrees)
printf("%s\n", $vertex->finalCardinal()); // SSE (SouthSouthEast)
printf("%d\n", $edge->initialBearing()); // 157 (degrees)
printf("%s\n", $edge->initialCardinal()); // SSE (SouthSouthEast)
printf("%d\n", $edge->finalBearing()); // 160 (degrees)
printf("%s\n", $edge->finalCardinal()); // SSE (SouthSouthEast)

$middlePoint = $vertex->middle(); // \League\Geotools\Coordinate\Coordinate
$middlePoint = $edge->middle(); // \League\Geotools\Coordinate\Coordinate
printf("%s\n", $middlePoint->getLatitude()); // 46.070143125815
printf("%s\n", $middlePoint->getLongitude()); // 3.9152401085931

$destinationPoint = $geotools->vertex()->setFrom($coordA)->destination(180, 200000); // \League\Geotools\Coordinate\Coordinate
$destinationPoint = $geotools->edge()->setFrom($coordA)->destination(180, 200000); // \League\Geotools\Coordinate\Coordinate
printf("%s\n", $destinationPoint->getLatitude()); // 47.026774650075
printf("%s\n", $destinationPoint->getLongitude()); // 2.3072664
```
Expand Down Expand Up @@ -438,19 +438,19 @@ $tenten = new \League\Geotools\Tests\Geohash\TenTen;
$tenten->encode(new Coordinate([51.09559, 1.12207])); // MEQ N6G 7NY5
```

## Vertex ##
## Edge ##

Represents a segment with a direction.
You can find if two vertexes are on the same line.
You can find if two edges are on the same line.

```php
<?php
$vertexA->setFrom(48.8234055);
$vertexA->setTo(2.3072664);
$edgeA->setFrom(48.8234055);
$edgeA->setTo(2.3072664);

$vertexB->setFrom(48.8234055);
$vertexB->setTo(2.3072664);
$vertexA->isOnSameLine($vertexB);
$edgeB->setFrom(48.8234055);
$edgeB->setTo(2.3072664);
$edgeA->isOnSameLine($edgeB);
```

## Polygon ##
Expand Down
14 changes: 7 additions & 7 deletions bin/geotools
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use League\Geotools\CLI\Command\Convert;
use League\Geotools\CLI\Command\Distance;
use League\Geotools\CLI\Command\Geocoder;
use League\Geotools\CLI\Command\Geohash;
use League\Geotools\CLI\Command\Vertex;
use League\Geotools\CLI\Command\Edge;
use League\Geotools\Geotools;

$geotools = new Geotools;
Expand All @@ -60,10 +60,10 @@ $console->add(new Geocoder\Geocode);
$console->add(new Geocoder\Reverse);
$console->add(new Geohash\Decode);
$console->add(new Geohash\Encode);
$console->add(new Vertex\Destination);
$console->add(new Vertex\FinalBearing);
$console->add(new Vertex\FinalCardinal);
$console->add(new Vertex\InitialBearing);
$console->add(new Vertex\InitialCardinal);
$console->add(new Vertex\Middle);
$console->add(new Edge\Destination);
$console->add(new Edge\FinalBearing);
$console->add(new Edge\FinalCardinal);
$console->add(new Edge\InitialBearing);
$console->add(new Edge\InitialCardinal);
$console->add(new Edge\Middle);
$console->run();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\CLI\Command\Vertex;
namespace League\Geotools\CLI\Command\Edge;

use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
Expand All @@ -31,7 +31,7 @@ protected function configure()
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();

$this
->setName('vertex:destination')
->setName('edge:destination')
->setDescription('Compute the destination coordinate with given bearing in degrees and a distance in meters')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('bearing', InputArgument::REQUIRED, 'The initial bearing in degrees')
Expand All @@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$from = new Coordinate($input->getArgument('origin'), Ellipsoid::createFromName($input->getOption('ellipsoid')));
$geotools = new Geotools;

$destination = $geotools->vertex()->setFrom($from);
$destination = $geotools->edge()->setFrom($from);
$destination = $destination->destination($input->getArgument('bearing'), $input->getArgument('distance'));

$output->writeln(sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\CLI\Command\Vertex;
namespace League\Geotools\CLI\Command\Edge;

use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
Expand All @@ -20,7 +20,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command-line vertex:final-bearing class
* Command-line edge:final-bearing class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
Expand All @@ -31,7 +31,7 @@ protected function configure()
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();

$this
->setName('vertex:final-bearing')
->setName('edge:final-bearing')
->setDescription('Compute the final bearing in degrees between 2 coordinates')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
Expand All @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf(
'<value>%s</value>',
$geotools->vertex()->setFrom($from)->setTo($to)->finalBearing()
$geotools->edge()->setFrom($from)->setTo($to)->finalBearing()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\CLI\Command\Vertex;
namespace League\Geotools\CLI\Command\Edge;

use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
Expand All @@ -20,7 +20,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command-line vertex:final-cardinal class
* Command-line edge:final-cardinal class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
Expand All @@ -31,7 +31,7 @@ protected function configure()
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();

$this
->setName('vertex:final-cardinal')
->setName('edge:final-cardinal')
->setDescription('Compute the final cardinal point (direction) between 2 coordinates')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
Expand All @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf(
'<value>%s</value>',
$geotools->vertex()->setFrom($from)->setTo($to)->finalCardinal()
$geotools->edge()->setFrom($from)->setTo($to)->finalCardinal()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\CLI\Command\Vertex;
namespace League\Geotools\CLI\Command\Edge;

use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
Expand All @@ -20,7 +20,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command-line vertex:initial-bearing class
* Command-line edge:initial-bearing class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
Expand All @@ -31,7 +31,7 @@ protected function configure()
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();

$this
->setName('vertex:initial-bearing')
->setName('edge:initial-bearing')
->setDescription('Compute the initial bearing in degrees between 2 coordinates')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
Expand All @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf(
'<value>%s</value>',
$geotools->vertex()->setFrom($from)->setTo($to)->initialBearing()
$geotools->edge()->setFrom($from)->setTo($to)->initialBearing()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\CLI\Command\Vertex;
namespace League\Geotools\CLI\Command\Edge;

use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
Expand All @@ -20,7 +20,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command-line vertex:initial-cardinal class
* Command-line edge:initial-cardinal class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
Expand All @@ -31,7 +31,7 @@ protected function configure()
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();

$this
->setName('vertex:initial-cardinal')
->setName('edge:initial-cardinal')
->setDescription('Compute the initial cardinal point (direction) between 2 coordinates')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
Expand All @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf(
'<value>%s</value>',
$geotools->vertex()->setFrom($from)->setTo($to)->initialCardinal()
$geotools->edge()->setFrom($from)->setTo($to)->initialCardinal()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\CLI\Command\Vertex;
namespace League\Geotools\CLI\Command\Edge;

use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
Expand All @@ -20,7 +20,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command-line vertex:middle class
* Command-line edge:middle class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
Expand All @@ -31,7 +31,7 @@ protected function configure()
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();

$this
->setName('vertex:middle')
->setName('edge:middle')
->setDescription('Compute the half-way coordinate between 2 coordinates')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
Expand All @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$to = new Coordinate($input->getArgument('destination'), $ellipsoid);

$geotools = new Geotools;
$middle = $geotools->vertex()->setFrom($from)->setTo($to)->middle();
$middle = $geotools->edge()->setFrom($from)->setTo($to)->middle();

$output->writeln(sprintf(
'<value>%s, %s</value>',
Expand Down
27 changes: 14 additions & 13 deletions src/Vertex/Vertex.php → src/Edge/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
* file that was distributed with this source code.
*/

namespace League\Geotools\Vertex;
namespace League\Geotools\Edge;

use League\Geotools\AbstractGeotools;
use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\CoordinateInterface;
use League\Geotools\Coordinate\Ellipsoid;

/**
* Vertex class
* Edge class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
class Vertex extends AbstractGeotools implements VertexInterface
class Edge extends AbstractGeotools implements EdgeInterface
{
/**
* @var integer
Expand Down Expand Up @@ -211,7 +211,7 @@ public function middle()
$lat3 = rad2deg(atan2(sin($latA) + sin($latB), sqrt((cos($latA) + $bx) * (cos($latA) + $bx) + $by * $by)));
$lng3 = rad2deg($lngA + atan2($by, cos($latA) + $bx));

return new Coordinate(array($lat3, $lng3), $this->from->getEllipsoid());
return new Coordinate([$lat3, $lng3], $this->from->getEllipsoid());
}

/**
Expand All @@ -235,23 +235,24 @@ public function destination($bearing, $distance)
$endLon = $lng + atan2(sin($bearing) * sin($distance / $this->from->getEllipsoid()->getA()) * cos($lat),
cos($distance / $this->from->getEllipsoid()->getA()) - sin($lat) * sin($endLat));

return new Coordinate(array(rad2deg($endLat), rad2deg($endLon)), $this->from->getEllipsoid());
return new Coordinate([rad2deg($endLat), rad2deg($endLon)], $this->from->getEllipsoid());
}

/**
* Returns true if the vertex passed on argument is on the same line as this object
* Returns true if the edge passed on argument is on the same line as this object
*
* @param Vertex $vertex The vertex to compare
* @return boolean
* @param Edge $edge The edge to compare
*
*@return boolean
*/
public function isOnSameLine(Vertex $vertex) {
if (is_null($this->getGradient()) && is_null($vertex->getGradient()) && $this->from->getLongitude() == $vertex->getFrom()->getLongitude()) {
public function isOnSameLine(Edge $edge) {
if (is_null($this->getGradient()) && is_null($edge->getGradient()) && $this->from->getLongitude() == $edge->getFrom()->getLongitude()) {
return true;
} elseif (!is_null($this->getGradient()) && !is_null($vertex->getGradient())) {
} elseif (!is_null($this->getGradient()) && !is_null($edge->getGradient())) {
return (
bccomp($this->getGradient(), $vertex->getGradient(), $this->getPrecision()) === 0
bccomp($this->getGradient(), $edge->getGradient(), $this->getPrecision()) === 0
&&
bccomp($this->getOrdinateIntercept(), $vertex->getOrdinateIntercept(), $this->getPrecision()) ===0
bccomp($this->getOrdinateIntercept(), $edge->getOrdinateIntercept(), $this->getPrecision()) ===0
);
} else {
return false;
Expand Down
Loading