/** * Class constructor. * * A LineString must be composed of 2 points or more, or 0 points for an empty LineString. * A LineString with exactly 1 point is not allowed. * * The coordinate system of each of the points must match the one of the LineString. * * @param CoordinateSystem $cs The coordinate system of the LineString. * @param Point ...$points The points that compose the LineString. * * @throws InvalidGeometryException If only one point was given. * @throws CoordinateSystemException If different coordinate systems are used. */ public function __construct(CoordinateSystem $cs, Point ...$points) { parent::__construct($cs, !$points); if (!$points) { return; } CoordinateSystem::check($this, ...$points); if (count($points) < 2) { throw new InvalidGeometryException('A LineString must be composed of at least 2 points.'); } $this->points = $points; }
/** * @param CoordinateSystem $cs * @param Point ...$points * * @return CircularString * * @throws InvalidGeometryException If the number of points is invalid. * @throws CoordinateSystemException If different coordinate systems are used. */ public function __construct(CoordinateSystem $cs, Point ...$points) { parent::__construct($cs, !$points); if (!$points) { return; } CoordinateSystem::check($this, ...$points); $numPoints = count($points); if ($numPoints < 3) { throw new InvalidGeometryException('A CircularString must be made of at least 3 points.'); } if ($numPoints % 2 === 0) { throw new InvalidGeometryException('A CircularString must have an odd number of points.'); } $this->points = $points; }
/** * Class constructor. * * The coordinate system of each of the curves must match the one of the CompoundCurve. * * @param CoordinateSystem $cs The coordinate system of the CompoundCurve. * @param Curve ...$curves The curves that compose the CompoundCurve. * * @throws EmptyGeometryException If any of the input curves is empty. * @throws InvalidGeometryException If the compound curve is not continuous. * @throws CoordinateSystemException If different coordinate systems are used. */ public function __construct(CoordinateSystem $cs, Curve ...$curves) { parent::__construct($cs, !$curves); if (!$curves) { return; } CoordinateSystem::check($this, ...$curves); /** @var Curve|null $previousCurve */ $previousCurve = null; foreach ($curves as $curve) { if ($previousCurve) { $endPoint = $previousCurve->endPoint(); $startPoint = $curve->startPoint(); if ($endPoint != $startPoint) { // on purpose by-value comparison! throw new InvalidGeometryException('Incontinuous compound curve.'); } } $previousCurve = $curve; } $this->curves = $curves; }