Skip to content

Commit

Permalink
Added support for Point::is3D() and isMeasured()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Sep 17, 2014
1 parent 3819af5 commit 4c48139
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Geometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function isSimple()
/**
* Returns true if this geometric object has z coordinate values.
*
* @todo add support for z coordinates
* @todo This should be abstract: each subclass should implement it.
*
* @return boolean
*/
Expand All @@ -242,7 +242,7 @@ public function is3D()
/**
* Returns true if this geometric object has m coordinate values.
*
* @todo add support for m coordinates
* @todo This should be abstract: each subclass should implement it.
*
* @return boolean
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,20 @@ public function isEmpty()
{
return false;
}

/**
* {@inheritdoc}
*/
public function is3D()
{
return $this->z !== null;
}

/**
* {@inheritdoc}
*/
public function isMeasured()
{
return $this->m !== null;
}
}
52 changes: 52 additions & 0 deletions tests/PointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,58 @@ public function testIsEmpty()
$this->assertFalse(Point::factory(0, 0)->isEmpty());
}

/**
* @dataProvider providerIs3D
*
* @param array $coordinates The point coordinates.
* @param boolean $is3D Whether the point is 3D.
*/
public function testIs3D(array $coordinates, $is3D)
{
/** @var Point $point */
$point = call_user_func_array([Point::class, 'factory'], $coordinates);
$this->assertSame($is3D, $point->is3D());
}

/**
* @return array
*/
public function providerIs3D()
{
return [
[[1.2, 3.4], false],
[[1.2, 3.4, 5.6], true],
[[1.2, 3.4, 5.6, 7.8], true],
[[1.2, 3.4, null, 7.8], false]
];
}

/**
* @dataProvider providerIsMeasured
*
* @param array $coordinates The point coordinates.
* @param boolean $isMeasured Whether the point is measured.
*/
public function testIsMeasured(array $coordinates, $isMeasured)
{
/** @var Point $point */
$point = call_user_func_array([Point::class, 'factory'], $coordinates);
$this->assertSame($isMeasured, $point->isMeasured());
}

/**
* @return array
*/
public function providerIsMeasured()
{
return [
[[1.2, 3.4], false],
[[1.2, 3.4, 5.6], false],
[[1.2, 3.4, 5.6, 7.8], true],
[[1.2, 3.4, null, 7.8], true]
];
}

/**
* @dataProvider providerEquals
*
Expand Down

0 comments on commit 4c48139

Please sign in to comment.