/** * @param CoordinateSystem $cs The coordinate system. * @param float ...$coords The point coordinates; can be empty for an empty point. * * @return Point * * @throws InvalidGeometryException If the number of coordinates does not match the coordinate system. */ public function __construct(CoordinateSystem $cs, ...$coords) { parent::__construct($cs, !$coords); if ($coords) { if (count($coords) !== $cs->coordinateDimension()) { throw new InvalidGeometryException(sprintf('Expected %d coordinates for Point %s, got %d.', $cs->coordinateDimension(), $cs->coordinateName(), count($coords))); } $this->x = (double) $coords[0]; $this->y = (double) $coords[1]; $hasZ = $cs->hasZ(); $hasM = $cs->hasM(); if ($hasZ) { $this->z = (double) $coords[2]; } if ($hasM) { $this->m = (double) $coords[$hasZ ? 3 : 2]; } } }
/** * Class constructor. * * @param CoordinateSystem $cs * @param Geometry ...$geometries * * @throws CoordinateSystemException If different coordinate systems are used. * @throws UnexpectedGeometryException If a geometry is not a valid type for a sub-class of GeometryCollection. */ public function __construct(CoordinateSystem $cs, Geometry ...$geometries) { $isEmpty = true; foreach ($geometries as $geometry) { if (!$geometry->isEmpty()) { $isEmpty = false; break; } } parent::__construct($cs, $isEmpty); if (!$geometries) { return; } CoordinateSystem::check($this, ...$geometries); $containedGeometryType = $this->containedGeometryType(); foreach ($geometries as $geometry) { if (!$geometry instanceof $containedGeometryType) { throw new UnexpectedGeometryException(sprintf('%s expects instance of %s, instance of %s given.', static::class, $containedGeometryType, get_class($geometry))); } } $this->geometries = $geometries; }