package ballistics.orbitalPoints.integrator.modDv

import ballistics.types.BallisticsError
import ballistics.types.EarthType
import ballistics.utils.atmosphere.getAtm62

internal class MDVFoto(earthType: EarthType) : AbstractMDV(earthType) {
    override fun calculate(x: Array<Double>): BallisticsError {
        prepare(x)
        y[0] = oma * x[3] + earth.wEarth * x[1] * 2
        y[1] = oma * x[4] - earth.wEarth * x[0] * 2
        y[2] = bca * x[5]

        y[3] = x[0]
        y[4] = x[1]
        y[5] = x[2]

        val h = r - earth.ekvRadius * (1 - earth.alphaEllips * fik)
        if (h < hminimum) {
            return BallisticsError.H_MINIMUM_ERROR
        }

        val ro = getAtm62(h, 6)

        val srv = v * ro * sBall

        y[0] -= srv * x[0]
        y[1] -= srv * x[1]
        y[2] -= srv * x[2]

        return BallisticsError.OK
    }
}
