"use strict";
/**
 * 타일 좌표 관련 유틸리티 함수
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTileBounds = getTileBounds;
exports.latLonToTile = latLonToTile;
exports.pixelToLatLon = pixelToLatLon;
exports.latLonToPixel = latLonToPixel;
exports.getDistance = getDistance;
/**
 * 타일 좌표를 위경도 범위로 변환
 */
function getTileBounds(z, x, y) {
    const n = Math.pow(2, z);
    const west = (x / n) * 360 - 180;
    const east = ((x + 1) / n) * 360 - 180;
    const north = Math.atan(Math.sinh(Math.PI * (1 - (2 * y) / n))) * (180 / Math.PI);
    const south = Math.atan(Math.sinh(Math.PI * (1 - (2 * (y + 1)) / n))) * (180 / Math.PI);
    return { west, south, east, north };
}
/**
 * 위경도를 타일 좌표로 변환
 */
function latLonToTile(lat, lon, zoom) {
    const latRad = (lat * Math.PI) / 180;
    const n = Math.pow(2, zoom);
    const x = Math.floor(((lon + 180) / 360) * n);
    const y = Math.floor(((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2) * n);
    return { x, y };
}
/**
 * 픽셀 좌표를 위경도로 변환
 */
function pixelToLatLon(x, y, z) {
    const size = Math.pow(2, z) * 256;
    const lon = (x / size) * 360 - 180;
    const n = Math.PI - (2 * Math.PI * y) / size;
    const lat = (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
    return { lat, lon };
}
/**
 * 위경도를 픽셀 좌표로 변환
 */
function latLonToPixel(lat, lon, z) {
    const size = Math.pow(2, z) * 256;
    const x = ((lon + 180) / 360) * size;
    const latRad = (lat * Math.PI) / 180;
    const y = ((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2) * size;
    return { x, y };
}
/**
 * 두 위경도 사이의 거리 계산 (Haversine 공식)
 */
function getDistance(lat1, lon1, lat2, lon2) {
    const R = 6371; // 지구 반경 (km)
    const dLat = (lat2 - lat1) * (Math.PI / 180);
    const dLon = (lon2 - lon1) * (Math.PI / 180);
    const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(lat1 * (Math.PI / 180)) * Math.cos(lat2 * (Math.PI / 180)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return R * c;
}
//# sourceMappingURL=tile-utils.js.map