package com.mogo.v2x.utils

import kotlin.math.asin
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt

internal class DistanceUtils {

    companion object {

        /**
         * @param lon1
         * @param lat1
         * @param lon2
         * @param lat2
         * @return 两坐标的距离 单位：米（M）
         */
        fun calculateLineDistance(lon1: Double, lat1: Double, lon2: Double, lat2: Double): Float {
            return try {
                var var2 = lon1
                var var4 = lat1
                var var6 = lon2
                var var8 = lat2
                var2 *= 0.01745329251994329
                var4 *= 0.01745329251994329
                var6 *= 0.01745329251994329
                var8 *= 0.01745329251994329
                val var10 = sin(var2)
                val var12 = sin(var4)
                val var14 = cos(var2)
                val var16 = cos(var4)
                val var18 = sin(var6)
                val var20 = sin(var8)
                val var22 = cos(var6)
                val var24 = cos(var8)
                val var28 = DoubleArray(3)
                val var29 = DoubleArray(3)
                var28[0] = var16 * var14
                var28[1] = var16 * var10
                var28[2] = var12
                var29[0] = var24 * var22
                var29[1] = var24 * var18
                var29[2] = var20
                (asin(sqrt((var28[0] - var29[0]) * (var28[0] - var29[0]) + (var28[1] - var29[1]) * (var28[1] - var29[1]) + (var28[2] - var29[2]) * (var28[2] - var29[2])) / 2.0) * 1.27420015798544E7).toFloat()
            } catch (var26: Throwable) {
                var26.printStackTrace()
                0.0f
            }
        }
    }
}