mirror of
https://gitee.com/niucloud-team/niucloud-admin.git
synced 2026-08-27 07:09:19 +00:00
44 lines
872 B
PHP
44 lines
872 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Location;
|
|
|
|
/**
|
|
* Trait GetBoundsTrait
|
|
*
|
|
* @package Location
|
|
*
|
|
* @property array<Coordinate> $points
|
|
*/
|
|
trait GetBoundsTrait
|
|
{
|
|
/**
|
|
* @return array<Coordinate>
|
|
*/
|
|
abstract public function getPoints(): array;
|
|
|
|
/**
|
|
* @return Bounds
|
|
*/
|
|
public function getBounds(): Bounds
|
|
{
|
|
$latMin = 90.0;
|
|
$latMax = -90.0;
|
|
$lngMin = 180.0;
|
|
$lngMax = -180.0;
|
|
|
|
foreach ($this->getPoints() as $point) {
|
|
$latMin = min($point->getLat(), $latMin);
|
|
$lngMin = min($point->getLng(), $lngMin);
|
|
$latMax = max($point->getLat(), $latMax);
|
|
$lngMax = max($point->getLng(), $lngMax);
|
|
}
|
|
|
|
return new Bounds(
|
|
new Coordinate($latMax, $lngMin),
|
|
new Coordinate($latMin, $lngMax)
|
|
);
|
|
}
|
|
}
|