Permalink
Browse files

Merge pull request #85 from codisart/add-get-determinant-method-for-v…

…ertex

[TECH] Add a method to vertex
  • Loading branch information...
toin0u committed Sep 5, 2017
2 parents 8fc0c6b + 667d5f7 commit 6df5448e976418d01e924559e70efb07cbc5ec41
Showing with 86 additions and 0 deletions.
  1. +19 −0 src/Vertex/Vertex.php
  2. +67 −0 tests/Vertex/VertexTest.php
View
@@ -275,4 +275,23 @@ public function getOtherCoordinate(CoordinateInterface $coordinate) {
return null;
}
/**
* Returns the determinant value between $this (vertex) and another vertex.
*
* @param Vertex $vertex [description]
* @return [type] [description]
*/
public function getDeterminant(Vertex $vertex) {
$abscissaVertexOne = $this->to->getLatitude() - $this->from->getLatitude();
$ordinateVertexOne = $this->to->getLongitude() - $this->from->getLongitude();
$abscissaVertexSecond = $vertex->getTo()->getLatitude() - $vertex->getFrom()->getLatitude();
$ordinateVertexSecond = $vertex->getTo()->getLongitude() - $vertex->getFrom()->getLongitude();
return bcsub(
bcmul($abscissaVertexOne, $ordinateVertexSecond, $this->precision),
bcmul($abscissaVertexSecond, $ordinateVertexOne, $this->precision),
$this->precision
);
}
}
@@ -473,4 +473,71 @@ public function VertexCoordinatesOriginalCoordinatesAndOtherOneProvider()
);
}
/**
* @dataProvider VertexCoordinatesAndExpectedDeterminantValueProvider
*/
public function testGetDeterminant($vertexCoordinatesFirst, $vertexCoordinatesSecond, $determinantValue)
{
$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->assertInstanceOf('League\Geotools\Vertex\Vertex', $this->vertex);
$this->assertInstanceOf('League\Geotools\Vertex\Vertex', $vertexToComp);
$this->assertEquals($determinantValue, $this->vertex->getDeterminant($vertexToComp));
}
public function VertexCoordinatesAndExpectedDeterminantValueProvider()
{
return array(
array(
array(
'from' => array(2, 5),
'to' => array(3, 7)
),
array(
'from' => array(14, 29),
'to' => array(-35, -69)
),
0
),
array(
array(
'from' => array(48.8234055, 2.3072664),
'to' => array(15.55886, 20.739423637488)
),
array(
'from' => array(56.2615, -1.8142427115944),
'to' => array(73.588101,45.703125)
),
'-1900.01027430'
),
array(
array(
'from' => array(1, 4),
'to' => array(2, 8)
),
array(
'from' => array(1, 4),
'to' => array(2, 7)
),
'-1'
),
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)
),
'-232.59698978'
),
);
}
}

0 comments on commit 6df5448

Please sign in to comment.