forked from mjaschen/phpgeo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start work on corridor around a line
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Location\Utility\Corridor; | ||
|
||
use Location\Bearing\BearingInterface; | ||
use Location\Line; | ||
use Location\Polygon; | ||
|
||
class LineCorridor | ||
{ | ||
/** | ||
* @var float distance between line and the corridor border, in meters | ||
*/ | ||
private $distance; | ||
|
||
/** | ||
* @var \Location\Bearing\BearingInterface | ||
*/ | ||
private $bearingCalculator; | ||
|
||
/** | ||
* LineCorridor constructor. | ||
* | ||
* @param float $distance | ||
*/ | ||
public function __construct($distance, BearingInterface $bearingCalculator) | ||
{ | ||
if ($distance <= 0.0) { | ||
throw new \InvalidArgumentException("distance must be greater than 0"); | ||
} | ||
|
||
$this->distance = $distance; | ||
$this->bearingCalculator = $bearingCalculator; | ||
} | ||
|
||
public function createCorridor(Line $line) | ||
{ | ||
throw new \RuntimeException("Method not implemented yet."); | ||
|
||
$corridor = new Polygon(); | ||
|
||
$bearingForward = $line->getBearing($this->bearingCalculator); | ||
$bearingReverse = $line->getReverse()->getBearing($this->bearingCalculator); | ||
|
||
$corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint1(), fmod($bearingForward + 135, 360), $this->distance)); | ||
$corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint1(), fmod($bearingForward - 135, 360), $this->distance)); | ||
$corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint2(), fmod($bearingReverse - 135, 360), $this->distance)); | ||
$corridor->addPoint($this->bearingCalculator->calculateDestination($line->getPoint2(), fmod($bearingReverse + 135, 360), $this->distance)); | ||
|
||
return $corridor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Location\Bearing\BearingEllipsoidal; | ||
use Location\Coordinate; | ||
use Location\Line; | ||
use Location\Utility\Corridor\LineCorridor; | ||
|
||
class LineCorridorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testIfZeroDistanceThrowsAnException() | ||
{ | ||
$instance = new LineCorridor(0, new BearingEllipsoidal()); | ||
} | ||
|
||
/** | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testIfNegativeDistanceThrowsAnException() | ||
{ | ||
$instance = new LineCorridor(-1, new BearingEllipsoidal()); | ||
} | ||
|
||
public function testIfSimpleLineCorridorWorksAsExpected() | ||
{ | ||
$line = new Line( | ||
new Coordinate(0, 0), | ||
new Coordinate(0.1, 0.1) | ||
); | ||
|
||
$instance = new LineCorridor(1000, new BearingEllipsoidal()); | ||
|
||
$corridor = $instance->createCorridor($line); | ||
} | ||
} |