using SatelliteProvider.Common.Utils;

namespace SatelliteProvider.Services.RouteManagement.TileProvision;

public static class TileResolutionHelper
{
    public static double ResolutionMetersPerPixel(int zoomLevel, double latitude, int tileSizePixels)
    {
        var latRad = latitude * Math.PI / 180.0;
        var metersPerPixel = (GeoUtils.EarthEquatorialCircumferenceMeters * Math.Cos(latRad))
            / (Math.Pow(2, zoomLevel) * tileSizePixels);
        return metersPerPixel;
    }

    public static double TileSizeMeters(int zoomLevel, double latitude, int tileSizePixels)
    {
        return ResolutionMetersPerPixel(zoomLevel, latitude, tileSizePixels) * tileSizePixels;
    }
}
