diff --git a/src/Geometry.php b/src/Geometry.php index f8e94ba8..4583757c 100644 --- a/src/Geometry.php +++ b/src/Geometry.php @@ -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 */ @@ -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 */ diff --git a/src/Point.php b/src/Point.php index 98896854..6d5524e8 100644 --- a/src/Point.php +++ b/src/Point.php @@ -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; + } } diff --git a/tests/PointTest.php b/tests/PointTest.php index 4582d600..0f305179 100644 --- a/tests/PointTest.php +++ b/tests/PointTest.php @@ -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 *