package ballistics.orbitalPoints

import ballistics.orbitalPoints.timeStepper.AbstractStepper
import ballistics.types.BallisticsError
import ballistics.types.EarthType
import ballistics.types.OrbitalPoint
import ballistics.types.RevolutionParameter
import ballistics.utils.earth.getEarth

abstract class AbstractOrbPointsCalculator(var earthType: EarthType) {
    val points = mutableListOf<OrbitalPoint>()
    val revolutions = mutableListOf<RevolutionParameter>()
    val earth = getEarth(earthType)
    var step = 60.0

    abstract fun calculate(
        tbegin: Double,
        tend: Double,
    ): BallisticsError

    abstract fun getStepper(): AbstractStepper

    protected abstract fun fastStep(t: Double): OrbitalPoint

    protected fun addRevolution(t: Double) {
        val p = fastStep(t)
        val blh = earth.xyz2blh(p.r)
        revolutions.add(RevolutionParameter(p, blh.long, blh.h))
    }

    protected fun equation(x: Double): Double {
        val p = fastStep(x)
        return p.r.z
    }

    fun clear(){
        points.clear()
        revolutions.clear()
    }
}
