智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
872 B

<?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)
);
}
}