package kr.lunaticbum.back.lun.utils

import kotlin.math.cos

val EARTH_RADIUS_METERS = 6371000
val LATITUDE_DEGREE_PER_METER: Double = 1.0 / (2 * Math.PI * EARTH_RADIUS_METERS / 360)

fun latitudeRange(latitude: Double, radiusInMeters: Int): DoubleArray {
    val degreeRange = radiusInMeters * LATITUDE_DEGREE_PER_METER

    val minLatitude = latitude - degreeRange
    val maxLatitude = latitude + degreeRange

    return doubleArrayOf(minLatitude, maxLatitude)
}

fun longitudeRange(latitude: Double, longitude: Double, radiusInMeters: Int): DoubleArray {
    val longitudeDegreePerMeter: Double = 360 / (2 * Math.PI * EARTH_RADIUS_METERS * cos(Math.toRadians(latitude)))
    val degreeRange = longitudeDegreePerMeter * radiusInMeters

    val minLongitude = longitude - degreeRange
    val maxLongitude = longitude + degreeRange

    return doubleArrayOf(minLongitude, maxLongitude)
}

//https://jinkpark.tistory.com/296
//https://develoyummer.tistory.com/103
//https://ghj1001020.tistory.com/300