diff --git a/README.md b/README.md index 7deb386..0a8534d 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 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 ## diff --git a/bin/geotools b/bin/geotools index 1b6b9d0..a8544db 100755 --- a/bin/geotools +++ b/bin/geotools @@ -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; @@ -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(); diff --git a/src/CLI/Command/Vertex/Destination.php b/src/CLI/Command/Edge/Destination.php similarity index 93% rename from src/CLI/Command/Vertex/Destination.php rename to src/CLI/Command/Edge/Destination.php index bafa1a0..cda353c 100644 --- a/src/CLI/Command/Vertex/Destination.php +++ b/src/CLI/Command/Edge/Destination.php @@ -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; @@ -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') @@ -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( diff --git a/src/CLI/Command/Vertex/FinalBearing.php b/src/CLI/Command/Edge/FinalBearing.php similarity index 90% rename from src/CLI/Command/Vertex/FinalBearing.php rename to src/CLI/Command/Edge/FinalBearing.php index 1b98077..26904bd 100644 --- a/src/CLI/Command/Vertex/FinalBearing.php +++ b/src/CLI/Command/Edge/FinalBearing.php @@ -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; @@ -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 */ @@ -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') @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf( '%s', - $geotools->vertex()->setFrom($from)->setTo($to)->finalBearing() + $geotools->edge()->setFrom($from)->setTo($to)->finalBearing() )); } } diff --git a/src/CLI/Command/Vertex/FinalCardinal.php b/src/CLI/Command/Edge/FinalCardinal.php similarity index 90% rename from src/CLI/Command/Vertex/FinalCardinal.php rename to src/CLI/Command/Edge/FinalCardinal.php index 8a82129..4e44386 100644 --- a/src/CLI/Command/Vertex/FinalCardinal.php +++ b/src/CLI/Command/Edge/FinalCardinal.php @@ -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; @@ -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 */ @@ -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') @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf( '%s', - $geotools->vertex()->setFrom($from)->setTo($to)->finalCardinal() + $geotools->edge()->setFrom($from)->setTo($to)->finalCardinal() )); } } diff --git a/src/CLI/Command/Vertex/InitialBearing.php b/src/CLI/Command/Edge/InitialBearing.php similarity index 90% rename from src/CLI/Command/Vertex/InitialBearing.php rename to src/CLI/Command/Edge/InitialBearing.php index 683b4aa..5b5790b 100644 --- a/src/CLI/Command/Vertex/InitialBearing.php +++ b/src/CLI/Command/Edge/InitialBearing.php @@ -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; @@ -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 */ @@ -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') @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf( '%s', - $geotools->vertex()->setFrom($from)->setTo($to)->initialBearing() + $geotools->edge()->setFrom($from)->setTo($to)->initialBearing() )); } } diff --git a/src/CLI/Command/Vertex/InitialCardinal.php b/src/CLI/Command/Edge/InitialCardinal.php similarity index 90% rename from src/CLI/Command/Vertex/InitialCardinal.php rename to src/CLI/Command/Edge/InitialCardinal.php index 6c6d807..7b7791e 100644 --- a/src/CLI/Command/Vertex/InitialCardinal.php +++ b/src/CLI/Command/Edge/InitialCardinal.php @@ -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; @@ -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 */ @@ -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') @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf( '%s', - $geotools->vertex()->setFrom($from)->setTo($to)->initialCardinal() + $geotools->edge()->setFrom($from)->setTo($to)->initialCardinal() )); } } diff --git a/src/CLI/Command/Vertex/Middle.php b/src/CLI/Command/Edge/Middle.php similarity index 91% rename from src/CLI/Command/Vertex/Middle.php rename to src/CLI/Command/Edge/Middle.php index ffadd15..c7ef16b 100644 --- a/src/CLI/Command/Vertex/Middle.php +++ b/src/CLI/Command/Edge/Middle.php @@ -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; @@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Command-line vertex:middle class + * Command-line edge:middle class * * @author Antoine Corcy */ @@ -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') @@ -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( '%s, %s', diff --git a/src/Vertex/Vertex.php b/src/Edge/Edge.php similarity index 88% rename from src/Vertex/Vertex.php rename to src/Edge/Edge.php index 5544158..115f003 100644 --- a/src/Vertex/Vertex.php +++ b/src/Edge/Edge.php @@ -9,7 +9,7 @@ * 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; @@ -17,11 +17,11 @@ use League\Geotools\Coordinate\Ellipsoid; /** - * Vertex class + * Edge class * * @author Antoine Corcy */ -class Vertex extends AbstractGeotools implements VertexInterface +class Edge extends AbstractGeotools implements EdgeInterface { /** * @var integer @@ -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()); } /** @@ -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; diff --git a/src/Vertex/VertexInterface.php b/src/Edge/EdgeInterface.php similarity index 77% rename from src/Vertex/VertexInterface.php rename to src/Edge/EdgeInterface.php index de42937..2f1eae3 100644 --- a/src/Vertex/VertexInterface.php +++ b/src/Edge/EdgeInterface.php @@ -9,23 +9,23 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Vertex; +namespace League\Geotools\Edge; use League\Geotools\Coordinate\CoordinateInterface; /** - * Vertex interface + * Edge interface * * @author Antoine Corcy */ -interface VertexInterface +interface EdgeInterface { /** * Set the origin coordinate. * * @param CoordinateInterface $from The origin coordinate. * - * @return VertexInterface + * @return EdgeInterface */ public function setFrom(CoordinateInterface $from); @@ -41,7 +41,7 @@ public function getFrom(); * * @param CoordinateInterface $to The destination coordinate. * - * @return VertexInterface + * @return EdgeInterface */ public function setTo(CoordinateInterface $to); @@ -53,14 +53,14 @@ public function setTo(CoordinateInterface $to); public function getTo(); /** - * Get the gradient (slope) of the vertex. + * Get the gradient (slope) of the edge. * * @return integer */ public function getGradient(); /** - * Get the ordinate (longitude) of the point where vertex intersects with the ordinate-axis (Prime-Meridian) of the coordinate system. + * Get the ordinate (longitude) of the point where edge intersects with the ordinate-axis (Prime-Meridian) of the coordinate system. * * @return integer */ diff --git a/src/Geotools.php b/src/Geotools.php index aacf947..e0d1ee1 100644 --- a/src/Geotools.php +++ b/src/Geotools.php @@ -11,13 +11,13 @@ namespace League\Geotools; +use Geocoder\Geocoder; +use League\Geotools\Batch\Batch; +use League\Geotools\Convert\Convert; use League\Geotools\Coordinate\CoordinateInterface; use League\Geotools\Distance\Distance; -use League\Geotools\Vertex\Vertex; -use League\Geotools\Batch\Batch; +use League\Geotools\Edge\Edge; use League\Geotools\Geohash\Geohash; -use League\Geotools\Convert\Convert; -use Geocoder\Geocoder; /** * Geotools class @@ -44,9 +44,9 @@ public function distance() /** * {@inheritDoc} */ - public function vertex() + public function edge() { - return new Vertex; + return new Edge; } /** diff --git a/src/GeotoolsInterface.php b/src/GeotoolsInterface.php index a1f7f43..dccc3dc 100644 --- a/src/GeotoolsInterface.php +++ b/src/GeotoolsInterface.php @@ -12,7 +12,12 @@ namespace League\Geotools; use Geocoder\Geocoder as GeocoderInterface; +use League\Geotools\Batch\BatchInterface; +use League\Geotools\Convert\ConvertInterface; use League\Geotools\Coordinate\CoordinateInterface; +use League\Geotools\Distance\DistanceInterface; +use League\Geotools\Edge\EdgeInterface; +use League\Geotools\Geohash\GeohashInterface; /** * Geotools interface @@ -29,11 +34,11 @@ interface GeotoolsInterface public function distance(); /** - * Returns an instance of Vertex. + * Returns an instance of Edge. * - * @return VertexInterface + * @return EdgeInterface */ - public function vertex(); + public function edge(); /** * Returns an instance of Batch. diff --git a/src/Polygon/Polygon.php b/src/Polygon/Polygon.php index 126ce69..4df0a5b 100644 --- a/src/Polygon/Polygon.php +++ b/src/Polygon/Polygon.php @@ -350,7 +350,7 @@ public function set($key, CoordinateInterface $coordinate = null) if (is_array($key)) { $values = $key; } elseif (null !== $coordinate) { - $values = array($key => $coordinate); + $values = [$key => $coordinate]; } else { throw new \InvalidArgumentException; } diff --git a/tests/CLI/Command/Vertex/DestinationTest.php b/tests/CLI/Command/Edge/DestinationTest.php similarity index 96% rename from tests/CLI/Command/Vertex/DestinationTest.php rename to tests/CLI/Command/Edge/DestinationTest.php index cf28530..3186c67 100644 --- a/tests/CLI/Command/Vertex/DestinationTest.php +++ b/tests/CLI/Command/Edge/DestinationTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Tests\CLI\Command\Vertex; +namespace League\Geotools\Tests\CLI\Command\Edge; use League\Geotools\CLI\Application; -use League\Geotools\CLI\Command\Vertex\Destination; +use League\Geotools\CLI\Command\Edge\Destination; use Symfony\Component\Console\Tester\CommandTester; /** @@ -29,7 +29,7 @@ protected function setUp() $this->application = new Application; $this->application->add(new Destination); - $this->command = $this->application->find('vertex:destination'); + $this->command = $this->application->find('edge:destination'); $this->commandTester = new CommandTester($this->command); } diff --git a/tests/CLI/Command/Vertex/FinalBearingTest.php b/tests/CLI/Command/Edge/FinalBearingTest.php similarity index 95% rename from tests/CLI/Command/Vertex/FinalBearingTest.php rename to tests/CLI/Command/Edge/FinalBearingTest.php index 5d740d1..fe77950 100644 --- a/tests/CLI/Command/Vertex/FinalBearingTest.php +++ b/tests/CLI/Command/Edge/FinalBearingTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Tests\CLI\Command\Vertex; +namespace League\Geotools\Tests\CLI\Command\Edge; use League\Geotools\CLI\Application; -use League\Geotools\CLI\Command\Vertex\FinalBearing; +use League\Geotools\CLI\Command\Edge\FinalBearing; use Symfony\Component\Console\Tester\CommandTester; /** @@ -29,7 +29,7 @@ protected function setUp() $this->application = new Application; $this->application->add(new FinalBearing); - $this->command = $this->application->find('vertex:final-bearing'); + $this->command = $this->application->find('edge:final-bearing'); $this->commandTester = new CommandTester($this->command); } diff --git a/tests/CLI/Command/Vertex/FinalCardinalTest.php b/tests/CLI/Command/Edge/FinalCardinalTest.php similarity index 95% rename from tests/CLI/Command/Vertex/FinalCardinalTest.php rename to tests/CLI/Command/Edge/FinalCardinalTest.php index 73e1a15..3b5c153 100644 --- a/tests/CLI/Command/Vertex/FinalCardinalTest.php +++ b/tests/CLI/Command/Edge/FinalCardinalTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Tests\CLI\Command\Vertex; +namespace League\Geotools\Tests\CLI\Command\Edge; use League\Geotools\CLI\Application; -use League\Geotools\CLI\Command\Vertex\FinalCardinal; +use League\Geotools\CLI\Command\Edge\FinalCardinal; use Symfony\Component\Console\Tester\CommandTester; /** @@ -29,7 +29,7 @@ protected function setUp() $this->application = new Application; $this->application->add(new FinalCardinal); - $this->command = $this->application->find('vertex:final-cardinal'); + $this->command = $this->application->find('edge:final-cardinal'); $this->commandTester = new CommandTester($this->command); } diff --git a/tests/CLI/Command/Vertex/InitialBearingTest.php b/tests/CLI/Command/Edge/InitialBearingTest.php similarity index 94% rename from tests/CLI/Command/Vertex/InitialBearingTest.php rename to tests/CLI/Command/Edge/InitialBearingTest.php index 5e19883..5e459ce 100644 --- a/tests/CLI/Command/Vertex/InitialBearingTest.php +++ b/tests/CLI/Command/Edge/InitialBearingTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Tests\CLI\Command\Vertex; +namespace League\Geotools\Tests\CLI\Command\Edge; use League\Geotools\CLI\Application; -use League\Geotools\CLI\Command\Vertex\InitialBearing; +use League\Geotools\CLI\Command\Edge\InitialBearing; use Symfony\Component\Console\Tester\CommandTester; /** @@ -29,7 +29,7 @@ protected function setUp() $this->application = new Application; $this->application->add(new InitialBearing); - $this->command = $this->application->find('vertex:initial-bearing'); + $this->command = $this->application->find('edge:initial-bearing'); $this->commandTester = new CommandTester($this->command); } diff --git a/tests/CLI/Command/Vertex/InitialCardinalTest.php b/tests/CLI/Command/Edge/InitialCardinalTest.php similarity index 94% rename from tests/CLI/Command/Vertex/InitialCardinalTest.php rename to tests/CLI/Command/Edge/InitialCardinalTest.php index 6d248af..59f99f5 100644 --- a/tests/CLI/Command/Vertex/InitialCardinalTest.php +++ b/tests/CLI/Command/Edge/InitialCardinalTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Tests\CLI\Command\Vertex; +namespace League\Geotools\Tests\CLI\Command\Edge; use League\Geotools\CLI\Application; -use League\Geotools\CLI\Command\Vertex\InitialCardinal; +use League\Geotools\CLI\Command\Edge\InitialCardinal; use Symfony\Component\Console\Tester\CommandTester; /** @@ -29,7 +29,7 @@ protected function setUp() $this->application = new Application; $this->application->add(new InitialCardinal); - $this->command = $this->application->find('vertex:initial-cardinal'); + $this->command = $this->application->find('edge:initial-cardinal'); $this->commandTester = new CommandTester($this->command); } diff --git a/tests/CLI/Command/Vertex/MiddleTest.php b/tests/CLI/Command/Edge/MiddleTest.php similarity index 95% rename from tests/CLI/Command/Vertex/MiddleTest.php rename to tests/CLI/Command/Edge/MiddleTest.php index 5dccda5..6870f2f 100644 --- a/tests/CLI/Command/Vertex/MiddleTest.php +++ b/tests/CLI/Command/Edge/MiddleTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace League\Geotools\Tests\CLI\Command\Vertex; +namespace League\Geotools\Tests\CLI\Command\Edge; use League\Geotools\CLI\Application; -use League\Geotools\CLI\Command\Vertex\Middle; +use League\Geotools\CLI\Command\Edge\Middle; use Symfony\Component\Console\Tester\CommandTester; /** @@ -29,7 +29,7 @@ protected function setUp() $this->application = new Application; $this->application->add(new Middle); - $this->command = $this->application->find('vertex:middle'); + $this->command = $this->application->find('edge:middle'); $this->commandTester = new CommandTester($this->command); } diff --git a/tests/Edge/EdgeTest.php b/tests/Edge/EdgeTest.php new file mode 100644 index 0000000..6097f93 --- /dev/null +++ b/tests/Edge/EdgeTest.php @@ -0,0 +1,477 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\Geotools\Tests\Edge; + +use League\Geotools\Coordinate\Coordinate; +use League\Geotools\Coordinate\Ellipsoid; +use League\Geotools\Edge\Edge; +use League\Geotools\Tests\TestCase; + +/** + * @author Antoine Corcy + */ +class EdgeTest extends TestCase +{ + protected $edge; + protected $from; + protected $to; + + protected function setUp() + { + $this->edge = new Edge(); + $this->from = $this->getStubCoordinate(); + $this->to = $this->getStubCoordinate(); + } + + public function testSetFromValueShouldBeACoordinateInterface() + { + $this->edge->setFrom($this->from); + $from = $this->edge->getFrom(); + + $this->assertTrue(is_object($from)); + $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $from); + } + + public function testSetFromShouldReturnTheSameEdgeInstance() + { + $edge = $this->edge->setFrom($this->from); + + $this->assertTrue(is_object($edge)); + $this->assertInstanceOf('League\Geotools\Edge\Edge', $edge); + $this->assertInstanceOf('League\Geotools\Edge\EdgeInterface', $edge); + $this->assertSame($this->edge, $edge); + } + + public function testSetToValueShouldBeACoordinateInterface() + { + $this->edge->setTo($this->to); + $to = $this->edge->getTo(); + + $this->assertTrue(is_object($to)); + $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $to); + } + + public function testSetToShouldReturnTheSameEdgeInstance() + { + $edge = $this->edge->setTo($this->to); + + $this->assertTrue(is_object($edge)); + $this->assertInstanceOf('League\Geotools\Edge\Edge', $edge); + $this->assertInstanceOf('League\Geotools\Edge\EdgeInterface', $edge); + $this->assertSame($this->edge, $edge); + } + + /** + * @dataProvider coordinatesAndExpectedDegreeForInitialBearingProvider + */ + public function testInitialBearing($from, $to, $expectedDegree) + { + $this->edge->setFrom($this->getMockCoordinateReturns($from)); + $this->edge->setTo($this->getMockCoordinateReturns($to)); + + $this->assertEquals($expectedDegree, $this->edge->initialBearing()); + } + + public function coordinatesAndExpectedDegreeForInitialBearingProvider() + { + return [ + [ + [48.8234055, 2.3072664], + [43.296482, 5.36978], + 157 + ], + [ + ['48.8234055', '2.3072664'], + ['43.296482', '5.36978'], + '157' + ], + [ + [43.296482, 5.36978], + [48.8234055, 2.3072664], + 340 + ], + [ + [-43.296482, -5.36978], + [-48.8234055, -2.3072664], + 160 + ], + [ + [35, 45], + [35, 135], + 60 + ], + ]; + } + + /** + * @dataProvider coordinatesAndExpectedDegreeForFinalBearingProvider + */ + public function testFinalBearing($from, $to, $expectedDegree) + { + $this->edge->setFrom($this->getMockCoordinateReturns($from)); + $this->edge->setTo($this->getMockCoordinateReturns($to)); + + $this->assertEquals($expectedDegree, $this->edge->finalBearing()); + } + + public function coordinatesAndExpectedDegreeForFinalBearingProvider() + { + return [ + [ + [48.8234055, 2.3072664], + [43.296482, 5.36978], + 160 + ], + [ + ['48.8234055', '2.3072664'], + ['43.296482', '5.36978'], + '160' + ], + [ + [43.296482, 5.36978], + [48.8234055, 2.3072664], + 337 + ], + [ + [-43.296482, -5.36978], + [-48.8234055, -2.3072664], + 157 + ], + [ + [35, 45], + [35, 135], + 119 + ], + ]; + } + + /** + * @dataProvider coordinatesAndExpectedInitialCardinalProvider + */ + public function testInitialCardinal($from, $to, $expectedCardinal) + { + $this->edge->setFrom($this->getMockCoordinateReturns($from)); + $this->edge->setTo($this->getMockCoordinateReturns($to)); + + $this->assertEquals($expectedCardinal, $this->edge->initialCardinal()); + } + + public function coordinatesAndExpectedInitialCardinalProvider() + { + return [ + [ + [48.8234055, 2.3072664], + [43.296482, 5.36978], + 'SSE' + ], + [ + ['28.8234055', '1.3072664'], + ['43.296482', '5.36978'], + 'N' + ], + [ + [43.296482, 5.36978], + [48.8234055, 2.3072664], + 'NNW' + ], + [ + [-13.296482, -5.36978], + [-38.8234055, -4.3072664], + 'S' + ], + [ + [35, 45], + [35, 135], + 'ENE' + ], + ]; + } + + /** + * @dataProvider coordinatesAndExpectedFinalCardinalProvider + */ + public function testFinalCardinal($from, $to, $expectedCardinal) + { + $this->edge->setFrom($this->getMockCoordinateReturns($from)); + $this->edge->setTo($this->getMockCoordinateReturns($to)); + + $this->assertEquals($expectedCardinal, $this->edge->finalCardinal()); + } + + public function coordinatesAndExpectedFinalCardinalProvider() + { + return [ + [ + [48.8234055, 2.3072664], + [43.296482, 5.36978], + 'SSE' + ], + [ + ['28.8234055', '1.3072664'], + ['43.296482', '5.36978'], + 'NNE' + ], + [ + [43.296482, 5.36978], + [48.8234055, 2.3072664], + 'NNW' + ], + [ + [-13.296482, -5.36978], + [-38.8234055, -4.3072664], + 'S' + ], + [ + [35, 45], + [35, 135], + 'ESE' + ], + ]; + } + + /** + * @dataProvider fromAndToCoordinatesAndExpectedMiddlePointProvider + */ + public function testMiddle($from, $to, $expectedMiddlePoint) + { + $this->edge->setFrom($this->getMockCoordinateReturns($from)); + $this->edge->setTo($this->getMockCoordinateReturns($to)); + $middlePoint = $this->edge->middle(); + + $this->assertTrue(is_object($middlePoint)); + $this->assertInstanceOf('League\Geotools\Coordinate\Coordinate', $middlePoint); + $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $middlePoint); + $this->assertEquals($expectedMiddlePoint->getLatitude(), $middlePoint->getLatitude()); + $this->assertEquals($expectedMiddlePoint->getLongitude(), $middlePoint->getLongitude()); + } + + public function fromAndToCoordinatesAndExpectedMiddlePointProvider() + { + return [ + [ + [48.8234055, 2.3072664], + [43.296482, 5.36978], + $this->getMockCoordinateReturns([46.070143125815, 3.9152401085931]) + ], + [ + ['28.8234055', '1.3072664'], + ['43.296482', '5.36978'], + $this->getMockCoordinateReturns([36.076935937133, 3.1506401291113]) + ], + [ + [43.296482, 5.36978], + [48.8234055, 2.3072664], + $this->getMockCoordinateReturns(['46.070143125815', '3.9152401085931']) + ], + [ + [-13.296482, -5.36978], + [-38.8234055, -4.3072664], + $this->getMockCoordinateReturns([-26.060903849478, -4.8973756901009]) + ], + ]; + } + + public function testMiddleShouldHaveTheSameEllipsoid() + { + $FOO = Ellipsoid::createFromArray([ + 'name' => 'foo ellipsoid', + 'a' => 123.0, + 'invF' => 456.0 + ]); + + $this->edge->setFrom($this->getMockCoordinateReturns([1, 2], $FOO)); + $this->edge->setTo($this->getMockCoordinateReturns([3, 4], $FOO)); + + $this->assertSame($this->edge->middle()->getEllipsoid(), $FOO); + } + + /** + * @dataProvider fromAndBearingAndDistanceAndExpectedDestinationPoint + */ + public function testDestination($from, $bearing, $distance, $expectedDestinationPoint) + { + $WGS84 = Ellipsoid::createFromName(Ellipsoid::WGS84); + + $this->edge->setFrom($this->getMockCoordinateReturns($from, $WGS84)); + $destinationPoint = $this->edge->destination($bearing, $distance); + + $this->assertTrue(is_object($destinationPoint)); + $this->assertInstanceOf('League\Geotools\Coordinate\Coordinate', $destinationPoint); + $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $destinationPoint); + $this->assertEquals($expectedDestinationPoint->getLatitude(), $destinationPoint->getLatitude()); + $this->assertEquals($expectedDestinationPoint->getLongitude(), $destinationPoint->getLongitude()); + } + + public function fromAndBearingAndDistanceAndExpectedDestinationPoint() + { + return [ + [ + [48.8234055, 2.3072664], + 180, + 200000, + $this->getMockCoordinateReturns([47.026774650075, 2.3072664]) + ], + [ + ['28.8234055', '1.3072664'], + 95, + 500000, + $this->getMockCoordinateReturns([28.336641152298, 6.3923716035552]) + ], + [ + [43.296482, 5.36978], + 37, + 3000, + $this->getMockCoordinateReturns(['43.318002633989', '5.3920718426221']) + ], + [ + [-13.296482, -5.36978], + 166, + 5000000, + $this->getMockCoordinateReturns([-56.057095935971, 12.44347001977]) + ], + ]; + } + + public function testDestinationShouldHaveTheSameEllipsoid() + { + $FOO = Ellipsoid::createFromArray([ + 'name' => 'foo ellipsoid', + 'a' => 123.0, + 'invF' => 456.0 + ]); + + $this->edge->setFrom($this->getMockCoordinateReturns([1, 2], $FOO)); + + $this->assertSame($this->edge->destination(123, 456)->getEllipsoid(), $FOO); + } + + /** + * @dataProvider EdgeCoordinatesAndExpectedSameLineStatusProvider + */ + public function testSameLine($edgeCoordinatesFirst, $edgeCoordinatesSecond, $sameLineStatus) + { + $this->edge->setFrom($this->getMockCoordinateReturns($edgeCoordinatesFirst['from'])); + $this->edge->setTo($this->getMockCoordinateReturns($edgeCoordinatesFirst['to'])); + $edgeToComp = new \League\Geotools\Edge\Edge; + $edgeToComp->setFrom($this->getMockCoordinateReturns($edgeCoordinatesSecond['from'])); + $edgeToComp->setTo($this->getMockCoordinateReturns($edgeCoordinatesSecond['to'])); + + $this->assertTrue(is_object($edgeToComp)); + $this->assertInstanceOf('League\Geotools\Edge\Edge', $this->edge); + $this->assertInstanceOf('League\Geotools\Edge\Edge', $edgeToComp); + $this->assertEquals($sameLineStatus, $this->edge->isOnSameLine($edgeToComp)); + } + + public function EdgeCoordinatesAndExpectedSameLineStatusProvider() + { + return [ + [ + [ + 'from' => [2, 5], + 'to' => [3, 7] + ], + [ + 'from' => [14, 29], + 'to' => [-35, -69] + ], + true + ], + [ + [ + 'from' => [48.8234055, 2.3072664], + 'to' => [43.296482, 5.36978] + ], + [ + 'from' => [56.2615, -1.8142427115944], + 'to' => [15.55886, 20.739423637488] + ], + true + ], + [ + [ + 'from' => [1, 4], + 'to' => [2, 8] + ], + [ + 'from' => [1, 4], + 'to' => [2, 7] + ], + false + ], + [ + [ + 'from' => [48.8234055, 2.3072664], + 'to' => [43.296482, 5.36978] + ], + [ + 'from' => [4.26116, 2.3072664], + 'to' => [68.5, 8.79635] + ], + false + ], + [ + [ + 'from' => [48.8234055, 2.3072664], + 'to' => [43.296482, 5.36978] + ], + [ + 'from' => [48.8234055, 2.3072664], + 'to' => [null, null] + ], + false + ], + ]; + } + + /** + * @dataProvider EdgeCoordinatesOriginalCoordinatesAndOtherOneProvider + */ + public function testGetOtherCoordinate($edgeCoordinates, $oneCoordinate, $otherCoordinate) + { + $this->edge->setFrom($edgeCoordinates['from']); + $this->edge->setTo($edgeCoordinates['to']); + + $this->assertInstanceOf('League\Geotools\Edge\Edge', $this->edge); + $this->assertEquals($otherCoordinate, $this->edge->getOtherCoordinate($oneCoordinate)); + } + + public function EdgeCoordinatesOriginalCoordinatesAndOtherOneProvider() + { + return [ + [ + [ + 'from' => new Coordinate([48.8234055, 2.3072664]), + 'to' => new Coordinate([43.296482, 5.36978]) + ], + new Coordinate([48.8234055, 2.3072664]), + new Coordinate([43.296482, 5.36978]) + ], + [ + [ + 'from' => new Coordinate([48.8234055, 2.3072664]), + 'to' => new Coordinate([43.296482, 5.36978]) + ], + new Coordinate([43.296482, 5.36978]), + new Coordinate([48.8234055, 2.3072664]) + ], + [ + [ + 'from' => new Coordinate([48.8234055, 2.3072664]), + 'to' => new Coordinate([43.296482, 5.36978]) + ], + new Coordinate([2, 5]), + null + ], + ]; + } + +} diff --git a/tests/GeotoolsTest.php b/tests/GeotoolsTest.php index 6562c15..5ad0bc9 100644 --- a/tests/GeotoolsTest.php +++ b/tests/GeotoolsTest.php @@ -35,13 +35,13 @@ public function testDistanceShouldReturnANewDistanceInstance() $this->assertInstanceOf('League\Geotools\Distance\DistanceInterface', $distance); } - public function testVertexShouldReturnANewVertexInstance() + public function testEdgeShouldReturnANewEdgeInstance() { - $vertex = $this->geotools->vertex(); + $edge = $this->geotools->edge(); - $this->assertTrue(is_object($vertex)); - $this->assertInstanceOf('League\Geotools\Vertex\Vertex', $vertex); - $this->assertInstanceOf('League\Geotools\Vertex\VertexInterface', $vertex); + $this->assertTrue(is_object($edge)); + $this->assertInstanceOf('League\Geotools\Edge\Edge', $edge); + $this->assertInstanceOf('League\Geotools\Edge\EdgeInterface', $edge); } public function testBatchShouldReturnANewBatchInstance() diff --git a/tests/Polygon/PolygonTest.php b/tests/Polygon/PolygonTest.php index b0eeda1..ae645db 100644 --- a/tests/Polygon/PolygonTest.php +++ b/tests/Polygon/PolygonTest.php @@ -47,16 +47,16 @@ public function testCannotCreatePolygonWithInteger() public function polygonCoordinates() { - return array( - array( - 'polygonCoordinates' => array( - array(48.9675969, 1.7440796), - array(48.4711003, 2.5268555), - array(48.9279131, 3.1448364), - array(49.3895245, 2.6119995) - ), - ), - ); + return [ + [ + 'polygonCoordinates' => [ + [48.9675969, 1.7440796], + [48.4711003, 2.5268555], + [48.9279131, 3.1448364], + [49.3895245, 2.6119995] + ], + ], + ]; } /** @@ -85,17 +85,17 @@ public function testArraySetterAndGetter($polygonCoordinates) public function polygonAndVertexCoordinate() { - return array( - array( - 'polygonCoordinates' => array( - array(48.9675969, 1.7440796), - array(48.4711003, 2.5268555), - array(48.9279131, 3.1448364), - array(49.3895245, 2.6119995) - ), - 'vertexCoordinate' => array(48.4711003, 2.5268555), - ), - ); + return [ + [ + 'polygonCoordinates' => [ + [48.9675969, 1.7440796], + [48.4711003, 2.5268555], + [48.9279131, 3.1448364], + [49.3895245, 2.6119995] + ], + 'vertexCoordinate' => [48.4711003, 2.5268555], + ], + ]; } /** @@ -116,33 +116,33 @@ public function testPointOnVertex($polygonCoordinates, $vertexCoordinate) public function testPointNotOnVertex($polygonCoordinates) { $this->polygon->set($polygonCoordinates); - $this->assertFalse($this->polygon->pointOnVertex(new Coordinate(array(0, 0)))); + $this->assertFalse($this->polygon->pointOnVertex(new Coordinate([0, 0]))); } public function polygonAndPointOnBoundaryCoordinate() { - return array( - array( - 'polygonCoordinates' => array( - array(48.9675969, 1.7440796), - array(48.4711003, 2.5268555), - array(48.9279131, 3.1448364), - array(49.3895245, 2.6119995) - ), - 'pointOnBoundaryCoordinates' => array( - array(48.7193486, 2.13546755), - array(48.6995067, 2.83584595), - array(49.1587188, 2.87841795), - array(49.1785607, 2.17803955), - ), - 'pointNotOnBoundaryCoordinates' => array( - array(43.7193486, 2.13546755), - array(45.6995067, 2.83584595), - array(47.1587188, 2.87841795), - array(20.1785607, 2.17803955), - ), - ), - ); + return [ + [ + 'polygonCoordinates' => [ + [48.9675969, 1.7440796], + [48.4711003, 2.5268555], + [48.9279131, 3.1448364], + [49.3895245, 2.6119995] + ], + 'pointOnBoundaryCoordinates' => [ + [48.7193486, 2.13546755], + [48.6995067, 2.83584595], + [49.1587188, 2.87841795], + [49.1785607, 2.17803955], + ], + 'pointNotOnBoundaryCoordinates' => [ + [43.7193486, 2.13546755], + [45.6995067, 2.83584595], + [47.1587188, 2.87841795], + [20.1785607, 2.17803955], + ], + ], + ]; } /** @@ -177,26 +177,26 @@ public function testPointNotOnBoundary( public function polygonAndPointInPolygonCoordinate() { - return array( - array( - 'polygonCoordinates' => array( - array(48.9675969, 1.7440796), - array(48.4711003, 2.5268555), - array(48.9279131, 3.1448364), - array(49.3895245, 2.6119995) - ), - 'pointInPolygonCoordinates' => array( - array(49.1785607, 2.4444580), - array(49.1785607, 2.0000000), - array(49.1785607, 1.7440796), - array(48.9279131, 2.4444580), - ), - 'pointNotInPolygonCoordinates' => array( - array(49.1785607, 5), - array(50, 2.4444580), - ) - ), - ); + return [ + [ + 'polygonCoordinates' => [ + [48.9675969, 1.7440796], + [48.4711003, 2.5268555], + [48.9279131, 3.1448364], + [49.3895245, 2.6119995] + ], + 'pointInPolygonCoordinates' => [ + [49.1785607, 2.4444580], + [49.1785607, 2.0000000], + [49.1785607, 1.7440796], + [48.9279131, 2.4444580], + ], + 'pointNotInPolygonCoordinates' => [ + [49.1785607, 5], + [50, 2.4444580], + ] + ], + ]; } /** diff --git a/tests/Vertex/VertexTest.php b/tests/Vertex/VertexTest.php deleted file mode 100644 index 9659f2d..0000000 --- a/tests/Vertex/VertexTest.php +++ /dev/null @@ -1,476 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace League\Geotools\Tests\Vertex; - -use League\Geotools\Coordinate\Coordinate; -use League\Geotools\Coordinate\Ellipsoid; -use League\Geotools\Vertex\Vertex; - -/** - * @author Antoine Corcy - */ -class VertexTest extends \League\Geotools\Tests\TestCase -{ - protected $vertex; - protected $from; - protected $to; - - protected function setUp() - { - $this->vertex = new Vertex; - $this->from = $this->getStubCoordinate(); - $this->to = $this->getStubCoordinate(); - } - - public function testSetFromValueShouldBeACoordinateInterface() - { - $this->vertex->setFrom($this->from); - $from = $this->vertex->getFrom(); - - $this->assertTrue(is_object($from)); - $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $from); - } - - public function testSetFromShouldReturnTheSameVertexInstance() - { - $vertex = $this->vertex->setFrom($this->from); - - $this->assertTrue(is_object($vertex)); - $this->assertInstanceOf('League\Geotools\Vertex\Vertex', $vertex); - $this->assertInstanceOf('League\Geotools\Vertex\VertexInterface', $vertex); - $this->assertSame($this->vertex, $vertex); - } - - public function testSetToValueShouldBeACoordinateInterface() - { - $this->vertex->setTo($this->to); - $to = $this->vertex->getTo(); - - $this->assertTrue(is_object($to)); - $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $to); - } - - public function testSetToShouldReturnTheSameVertexInstance() - { - $vertex = $this->vertex->setTo($this->to); - - $this->assertTrue(is_object($vertex)); - $this->assertInstanceOf('League\Geotools\Vertex\Vertex', $vertex); - $this->assertInstanceOf('League\Geotools\Vertex\VertexInterface', $vertex); - $this->assertSame($this->vertex, $vertex); - } - - /** - * @dataProvider coordinatesAndExpectedDegreeForInitialBearingProvider - */ - public function testInitialBearing($from, $to, $expectedDegree) - { - $this->vertex->setFrom($this->getMockCoordinateReturns($from)); - $this->vertex->setTo($this->getMockCoordinateReturns($to)); - - $this->assertEquals($expectedDegree, $this->vertex->initialBearing()); - } - - public function coordinatesAndExpectedDegreeForInitialBearingProvider() - { - return array( - array( - array(48.8234055, 2.3072664), - array(43.296482, 5.36978), - 157 - ), - array( - array('48.8234055', '2.3072664'), - array('43.296482', '5.36978'), - '157' - ), - array( - array(43.296482, 5.36978), - array(48.8234055, 2.3072664), - 340 - ), - array( - array(-43.296482, -5.36978), - array(-48.8234055, -2.3072664), - 160 - ), - array( - array(35, 45), - array(35, 135), - 60 - ), - ); - } - - /** - * @dataProvider coordinatesAndExpectedDegreeForFinalBearingProvider - */ - public function testFinalBearing($from, $to, $expectedDegree) - { - $this->vertex->setFrom($this->getMockCoordinateReturns($from)); - $this->vertex->setTo($this->getMockCoordinateReturns($to)); - - $this->assertEquals($expectedDegree, $this->vertex->finalBearing()); - } - - public function coordinatesAndExpectedDegreeForFinalBearingProvider() - { - return array( - array( - array(48.8234055, 2.3072664), - array(43.296482, 5.36978), - 160 - ), - array( - array('48.8234055', '2.3072664'), - array('43.296482', '5.36978'), - '160' - ), - array( - array(43.296482, 5.36978), - array(48.8234055, 2.3072664), - 337 - ), - array( - array(-43.296482, -5.36978), - array(-48.8234055, -2.3072664), - 157 - ), - array( - array(35, 45), - array(35, 135), - 119 - ), - ); - } - - /** - * @dataProvider coordinatesAndExpectedInitialCardinalProvider - */ - public function testInitialCardinal($from, $to, $expectedCardinal) - { - $this->vertex->setFrom($this->getMockCoordinateReturns($from)); - $this->vertex->setTo($this->getMockCoordinateReturns($to)); - - $this->assertEquals($expectedCardinal, $this->vertex->initialCardinal()); - } - - public function coordinatesAndExpectedInitialCardinalProvider() - { - return array( - array( - array(48.8234055, 2.3072664), - array(43.296482, 5.36978), - 'SSE' - ), - array( - array('28.8234055', '1.3072664'), - array('43.296482', '5.36978'), - 'N' - ), - array( - array(43.296482, 5.36978), - array(48.8234055, 2.3072664), - 'NNW' - ), - array( - array(-13.296482, -5.36978), - array(-38.8234055, -4.3072664), - 'S' - ), - array( - array(35, 45), - array(35, 135), - 'ENE' - ), - ); - } - - /** - * @dataProvider coordinatesAndExpectedFinalCardinalProvider - */ - public function testFinalCardinal($from, $to, $expectedCardinal) - { - $this->vertex->setFrom($this->getMockCoordinateReturns($from)); - $this->vertex->setTo($this->getMockCoordinateReturns($to)); - - $this->assertEquals($expectedCardinal, $this->vertex->finalCardinal()); - } - - public function coordinatesAndExpectedFinalCardinalProvider() - { - return array( - array( - array(48.8234055, 2.3072664), - array(43.296482, 5.36978), - 'SSE' - ), - array( - array('28.8234055', '1.3072664'), - array('43.296482', '5.36978'), - 'NNE' - ), - array( - array(43.296482, 5.36978), - array(48.8234055, 2.3072664), - 'NNW' - ), - array( - array(-13.296482, -5.36978), - array(-38.8234055, -4.3072664), - 'S' - ), - array( - array(35, 45), - array(35, 135), - 'ESE' - ), - ); - } - - /** - * @dataProvider fromAndToCoordinatesAndExpectedMiddlePointProvider - */ - public function testMiddle($from, $to, $expectedMiddlePoint) - { - $this->vertex->setFrom($this->getMockCoordinateReturns($from)); - $this->vertex->setTo($this->getMockCoordinateReturns($to)); - $middlePoint = $this->vertex->middle(); - - $this->assertTrue(is_object($middlePoint)); - $this->assertInstanceOf('League\Geotools\Coordinate\Coordinate', $middlePoint); - $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $middlePoint); - $this->assertEquals($expectedMiddlePoint->getLatitude(), $middlePoint->getLatitude()); - $this->assertEquals($expectedMiddlePoint->getLongitude(), $middlePoint->getLongitude()); - } - - public function fromAndToCoordinatesAndExpectedMiddlePointProvider() - { - return array( - array( - array(48.8234055, 2.3072664), - array(43.296482, 5.36978), - $this->getMockCoordinateReturns(array(46.070143125815, 3.9152401085931)) - ), - array( - array('28.8234055', '1.3072664'), - array('43.296482', '5.36978'), - $this->getMockCoordinateReturns(array(36.076935937133, 3.1506401291113)) - ), - array( - array(43.296482, 5.36978), - array(48.8234055, 2.3072664), - $this->getMockCoordinateReturns(array('46.070143125815', '3.9152401085931')) - ), - array( - array(-13.296482, -5.36978), - array(-38.8234055, -4.3072664), - $this->getMockCoordinateReturns(array(-26.060903849478, -4.8973756901009)) - ), - ); - } - - public function testMiddleShouldHaveTheSameEllipsoid() - { - $FOO = Ellipsoid::createFromArray(array( - 'name' => 'foo ellipsoid', - 'a' => 123.0, - 'invF' => 456.0 - )); - - $this->vertex->setFrom($this->getMockCoordinateReturns(array(1, 2), $FOO)); - $this->vertex->setTo($this->getMockCoordinateReturns(array(3, 4), $FOO)); - - $this->assertSame($this->vertex->middle()->getEllipsoid(), $FOO); - } - - /** - * @dataProvider fromAndBearingAndDistanceAndExpectedDestinationPoint - */ - public function testDestination($from, $bearing, $distance, $expectedDestinationPoint) - { - $WGS84 = Ellipsoid::createFromName(Ellipsoid::WGS84); - - $this->vertex->setFrom($this->getMockCoordinateReturns($from, $WGS84)); - $destinationPoint = $this->vertex->destination($bearing, $distance); - - $this->assertTrue(is_object($destinationPoint)); - $this->assertInstanceOf('League\Geotools\Coordinate\Coordinate', $destinationPoint); - $this->assertInstanceOf('League\Geotools\Coordinate\CoordinateInterface', $destinationPoint); - $this->assertEquals($expectedDestinationPoint->getLatitude(), $destinationPoint->getLatitude()); - $this->assertEquals($expectedDestinationPoint->getLongitude(), $destinationPoint->getLongitude()); - } - - public function fromAndBearingAndDistanceAndExpectedDestinationPoint() - { - return array( - array( - array(48.8234055, 2.3072664), - 180, - 200000, - $this->getMockCoordinateReturns(array(47.026774650075, 2.3072664)) - ), - array( - array('28.8234055', '1.3072664'), - 95, - 500000, - $this->getMockCoordinateReturns(array(28.336641152298, 6.3923716035552)) - ), - array( - array(43.296482, 5.36978), - 37, - 3000, - $this->getMockCoordinateReturns(array('43.318002633989', '5.3920718426221')) - ), - array( - array(-13.296482, -5.36978), - 166, - 5000000, - $this->getMockCoordinateReturns(array(-56.057095935971, 12.44347001977)) - ), - ); - } - - public function testDestinationShouldHaveTheSameEllipsoid() - { - $FOO = Ellipsoid::createFromArray(array( - 'name' => 'foo ellipsoid', - 'a' => 123.0, - 'invF' => 456.0 - )); - - $this->vertex->setFrom($this->getMockCoordinateReturns(array(1, 2), $FOO)); - - $this->assertSame($this->vertex->destination(123, 456)->getEllipsoid(), $FOO); - } - - /** - * @dataProvider VertexCoordinatesAndExpectedSameLineStatusProvider - */ - public function testSameLine($vertexCoordinatesFirst, $vertexCoordinatesSecond, $sameLineStatus) - { - $this->vertex->setFrom($this->getMockCoordinateReturns($vertexCoordinatesFirst['from'])); - $this->vertex->setTo($this->getMockCoordinateReturns($vertexCoordinatesFirst['to'])); - $vertexToComp = new Vertex; - $vertexToComp->setFrom($this->getMockCoordinateReturns($vertexCoordinatesSecond['from'])); - $vertexToComp->setTo($this->getMockCoordinateReturns($vertexCoordinatesSecond['to'])); - - $this->assertTrue(is_object($vertexToComp)); - $this->assertInstanceOf('League\Geotools\Vertex\Vertex', $this->vertex); - $this->assertInstanceOf('League\Geotools\Vertex\Vertex', $vertexToComp); - $this->assertEquals($sameLineStatus, $this->vertex->isOnSameLine($vertexToComp)); - } - - public function VertexCoordinatesAndExpectedSameLineStatusProvider() - { - return array( - array( - array( - 'from' => array(2, 5), - 'to' => array(3, 7) - ), - array( - 'from' => array(14, 29), - 'to' => array(-35, -69) - ), - true - ), - array( - array( - 'from' => array(48.8234055, 2.3072664), - 'to' => array(43.296482, 5.36978) - ), - array( - 'from' => array(56.2615, -1.8142427115944), - 'to' => array(15.55886, 20.739423637488) - ), - true - ), - array( - array( - 'from' => array(1, 4), - 'to' => array(2, 8) - ), - array( - 'from' => array(1, 4), - 'to' => array(2, 7) - ), - false - ), - array( - array( - 'from' => array(48.8234055, 2.3072664), - 'to' => array(43.296482, 5.36978) - ), - array( - 'from' => array(4.26116, 2.3072664), - 'to' => array(68.5, 8.79635) - ), - false - ), - array( - array( - 'from' => array(48.8234055, 2.3072664), - 'to' => array(43.296482, 5.36978) - ), - array( - 'from' => array(48.8234055, 2.3072664), - 'to' => array(null, null) - ), - false - ), - ); - } - - /** - * @dataProvider VertexCoordinatesOriginalCoordinatesAndOtherOneProvider - */ - public function testGetOtherCoordinate($vertexCoordinates, $oneCoordinate, $otherCoordinate) - { - $this->vertex->setFrom($vertexCoordinates['from']); - $this->vertex->setTo($vertexCoordinates['to']); - - $this->assertInstanceOf('League\Geotools\Vertex\Vertex', $this->vertex); - $this->assertEquals($otherCoordinate, $this->vertex->getOtherCoordinate($oneCoordinate)); - } - - public function VertexCoordinatesOriginalCoordinatesAndOtherOneProvider() - { - return array( - array( - array( - 'from' => new Coordinate(array(48.8234055, 2.3072664)), - 'to' => new Coordinate(array(43.296482, 5.36978)) - ), - new Coordinate(array(48.8234055, 2.3072664)), - new Coordinate(array(43.296482, 5.36978)) - ), - array( - array( - 'from' => new Coordinate(array(48.8234055, 2.3072664)), - 'to' => new Coordinate(array(43.296482, 5.36978)) - ), - new Coordinate(array(43.296482, 5.36978)), - new Coordinate(array(48.8234055, 2.3072664)) - ), - array( - array( - 'from' => new Coordinate(array(48.8234055, 2.3072664)), - 'to' => new Coordinate(array(43.296482, 5.36978)) - ), - new Coordinate(array(2, 5)), - null - ), - ); - } - -}