| @@ 8-42 (lines=35) @@ | ||
| 5 | use PHPAlgorithms\GraphTools\Interfaces\PointInterface; |
|
| 6 | use PHPAlgorithms\GraphTools\Exceptions\PointException; |
|
| 7 | ||
| 8 | class Point3D extends Point2D implements PointInterface { |
|
| 9 | protected $z; |
|
| 10 | ||
| 11 | protected function checkZ($z) |
|
| 12 | { |
|
| 13 | if (!is_numeric($z)) { |
|
| 14 | throw new PointException("z: {$z} must be numeric value"); |
|
| 15 | } |
|
| 16 | } |
|
| 17 | ||
| 18 | public function __construct($x, $y, $z) |
|
| 19 | { |
|
| 20 | parent::__construct($x, $y); |
|
| 21 | ||
| 22 | $this->checkZ($z); |
|
| 23 | ||
| 24 | $this->z = $z; |
|
| 25 | } |
|
| 26 | ||
| 27 | public function move($x = 0, $y = 0, $z = 0) |
|
| 28 | { |
|
| 29 | parent::move($x, $y); |
|
| 30 | ||
| 31 | $this->checkZ($z); |
|
| 32 | ||
| 33 | $this->z += $z; |
|
| 34 | ||
| 35 | return $this; |
|
| 36 | } |
|
| 37 | ||
| 38 | public function lowerDimension() |
|
| 39 | { |
|
| 40 | return new Point2D($this->x, $this->y); |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| @@ 8-42 (lines=35) @@ | ||
| 5 | use PHPAlgorithms\GraphTools\Interfaces\PointInterface; |
|
| 6 | use PHPAlgorithms\GraphTools\Exceptions\PointException; |
|
| 7 | ||
| 8 | class Point4D extends Point3D implements PointInterface { |
|
| 9 | protected $t; |
|
| 10 | ||
| 11 | protected function checkT($t) |
|
| 12 | { |
|
| 13 | if (!is_numeric($t)) { |
|
| 14 | throw new PointException("t: {$t} must be numeric value"); |
|
| 15 | } |
|
| 16 | } |
|
| 17 | ||
| 18 | public function __construct($x, $y, $z, $t) |
|
| 19 | { |
|
| 20 | parent::__construct($x, $y, $z); |
|
| 21 | ||
| 22 | $this->checkT($t); |
|
| 23 | ||
| 24 | $this->t = $t; |
|
| 25 | } |
|
| 26 | ||
| 27 | public function move($x = 0, $y = 0, $z = 0, $t = 0) |
|
| 28 | { |
|
| 29 | parent::move($x, $y, $z); |
|
| 30 | ||
| 31 | $this->checkT($t); |
|
| 32 | ||
| 33 | $this->t += $t; |
|
| 34 | ||
| 35 | return $this; |
|
| 36 | } |
|
| 37 | ||
| 38 | public function lowerDimension() |
|
| 39 | { |
|
| 40 | return new Point3D($this->x, $this->y, $this->z); |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||