heymoon-cc/php-vector-tile-data-provider

View on GitHub
src/Helper/GeometryHelper.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace HeyMoon\VectorTileDataProvider\Helper;

use Brick\Geo\Exception\CoordinateSystemException;
use Brick\Geo\Exception\EmptyGeometryException;
use Brick\Geo\Exception\InvalidGeometryException;
use Brick\Geo\LineString;
use Brick\Geo\Point;
use Brick\Geo\Polygon;
use HeyMoon\VectorTileDataProvider\Spatial\WebMercatorProjection;
use HeyMoon\VectorTileDataProvider\Entity\TilePosition;

/**
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
class GeometryHelper
{
    private static array $grids = [];

    public static function getGridSize(int $zoom): int
    {
        return static::$grids[$zoom] ?? (static::$grids[$zoom] = (int)pow(2, $zoom));
    }

    public static function getTileWidth(int $zoom): float
    {
        return (WebMercatorProjection::EARTH_RADIUS * 2) / static::getGridSize($zoom);
    }
}