<commit_before>﻿using System;
using System.Reflection;
using UnityEngine;

namespace Trajectories
{
    class FARModel : VesselAerodynamicModel
    {
        private MethodInfo FARAPI_CalculateVesselAeroForces;

        public override string AerodynamicModelName { get { return "FAR"; } }

        public FARModel(Vessel ship, CelestialBody body, MethodInfo CalculateVesselAeroForces)
            : base(ship, body)
        {
            FARAPI_CalculateVesselAeroForces = CalculateVesselAeroForces;
        }

        protected override Vector3d ComputeForces_Model(Vector3d airVelocity, double altitude)
        {
            //Debug.Log("Trajectories: getting FAR forces");
            if (vessel_.packed) { return Vector3.zero; }
            Vector3 worldAirVel = new Vector3((float)airVelocity.x, (float)airVelocity.y, (float)airVelocity.z);
            var parameters = new object[] { vessel_, new Vector3(), new Vector3(), worldAirVel, altitude };
            FARAPI_CalculateVesselAeroForces.Invoke(null, parameters);
            return (Vector3)parameters[1];
        }

        public override Vector2 PackForces(Vector3d forces, double altitudeAboveSea, double velocity)
        {
            double rho = StockAeroUtil.GetDensity(altitudeAboveSea, body_); // would be even better to use FAR method of computing the air density (which also depends on velocity), but this is already better than nothing

            if (rho < 0.0000000001)
                return new Vector2(0, 0);
            double invScale = 1.0 / (rho * Math.Max(1.0, velocity * velocity));<commit_msg>FARModel: Catch zero velocity from passing to FAR<commit_after>﻿using System;
using System.Reflection;
using UnityEngine;

namespace Trajectories
{
    class FARModel: VesselAerodynamicModel
    {
        private MethodInfo FARAPI_CalculateVesselAeroForces;

        public override string AerodynamicModelName { get { return "FAR"; } }

        public FARModel(Vessel ship, CelestialBody body, MethodInfo CalculateVesselAeroForces)
            : base(ship, body)
        {
            FARAPI_CalculateVesselAeroForces = CalculateVesselAeroForces;
        }

        protected override Vector3d ComputeForces_Model(Vector3d airVelocity, double altitude)
        {
            //Debug.Log("Trajectories: getting FAR forces");
            if (vessel_ == null || vessel_.packed)
                return Vector3.zero;

            if (airVelocity.x == 0d || airVelocity.y == 0d || airVelocity.z == 0d)
            {
                //Debug.LogWarning(string.Format("Trajectories: Getting FAR forces - Velocity: {0} | Altitude: {1}", airVelocity, altitude));
                return Vector3.zero;
            }

            Vector3 worldAirVel = new Vector3((float)airVelocity.x, (float)airVelocity.y, (float)airVelocity.z);
            var parameters = new object[] { vessel_, new Vector3(), new Vector3(), worldAirVel, altitude };
            FARAPI_CalculateVesselAeroForces.Invoke(null, parameters);
            return (Vector3)parameters[1];
        }

        public override Vector2 PackForces(Vector3d forces, double altitudeAboveSea, double velocity)
        {
            double rho = StockAeroUtil.GetDensity(altitudeAboveSea, body_); // would be even better to use FAR method of computing the air density (which also depends on velocity), but this is already better than nothing

            if (rho < 0.0000000001)
                return new Vector2(0, 0);
            double invScale = 1.0 / (rho * Math.Max(1.0, velocity * velocity));
{'fraction_non_alphanumeric': 0.08508224617129892, 'fraction_numerical': 0.018150879183210438, 'mean_word_length': 2.7362288135593222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919849', 'n_tokens_mistral': 1046, 'n_tokens_neox': 954, 'n_words': 267}