< Summary

Information
Class: CounterDrone.Core.Simulation.MunitionEntity
Assembly: CounterDrone.Core
File(s): C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Simulation\MunitionEntity.cs
Line coverage
82%
Covered lines: 47
Uncovered lines: 10
Coverable lines: 57
Total lines: 87
Line coverage: 82.4%
Branch coverage
71%
Covered branches: 10
Total branches: 14
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_LaunchMode()100%11100%
get_AerosolType()100%11100%
get_PosX()100%11100%
get_PosY()100%11100%
get_PosZ()100%11100%
get_TargetX()100%11100%
get_TargetY()100%11100%
get_TargetZ()100%11100%
get_ReleaseAltitude()100%11100%
get_HasArrived()100%11100%
.ctor(...)50%22100%
Update(...)75%191262.96%

File(s)

C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Simulation\MunitionEntity.cs

#LineLine coverage
 1using CounterDrone.Core.Algorithms;
 2using CounterDrone.Core.Models;
 3
 4namespace CounterDrone.Core.Simulation
 5{
 6    public class MunitionEntity
 7    {
 118        public string Id { get; }
 7379        public PlatformType LaunchMode { get; }
 1110        public AerosolType AerosolType { get; }
 75511        public float PosX { get; private set; }
 177112        public float PosY { get; private set; }
 75513        public float PosZ { get; private set; }
 1314        public float TargetX { get; }
 1115        public float TargetY { get; }
 1316        public float TargetZ { get; }
 101817        public float ReleaseAltitude { get; }
 148618        public bool HasArrived { get; private set; }
 19
 20        private readonly float _muzzleVelocity;
 21        private float _time;
 22        private readonly float _launchAngle;
 23        private readonly float _azimuth;
 24        private readonly float _startX, _startY, _startZ;
 25
 26        private bool _hasExceededReleaseAltitude;
 27
 1428        public MunitionEntity(string id, PlatformType launchMode, AerosolType aerosolType,
 1429            float startX, float startY, float startZ,
 1430            float targetX, float targetY, float targetZ,
 1431            float muzzleVelocity, float releaseAltitude)
 1432        {
 1433            Id = id;
 1434            LaunchMode = launchMode;
 1435            AerosolType = aerosolType;
 4236            _startX = startX; _startY = startY; _startZ = startZ;
 4237            PosX = startX; PosY = startY; PosZ = startZ;
 4238            TargetX = targetX; TargetY = targetY; TargetZ = targetZ;
 1439            _muzzleVelocity = muzzleVelocity;
 1440            ReleaseAltitude = releaseAltitude;
 41
 42            // 根据目标距离反算发射角(取低弹道)
 1443            var dx = targetX - startX;
 1444            var dz = targetZ - startZ;
 1445            var horizontalDist = (float)System.Math.Sqrt(dx * dx + dz * dz);
 1446            _azimuth = horizontalDist > 0.001f ? (float)System.Math.Atan2(dx, dz) : 0;
 47
 1448            _launchAngle = Kinematics.CalculateLaunchAngle(horizontalDist, muzzleVelocity, releaseAltitude);
 1449        }
 50
 51        public void Update(float deltaTime)
 73752        {
 73753            if (HasArrived) return;
 73754            _time += deltaTime;
 55
 73756            if (LaunchMode == PlatformType.GroundBased)
 73757            {
 73758                (float x, float y, float z) = Kinematics.ParabolicPosition(
 73759                    _startX, _startY, _startZ, _launchAngle, _azimuth, _muzzleVelocity, _time);
 221160                PosX = x; PosY = y; PosZ = z;
 61
 62                // 必须先从上方越过释放高度,再回落时才触发
 73763                if (PosY > ReleaseAltitude)
 25764                    _hasExceededReleaseAltitude = true;
 65
 73766                if (_hasExceededReleaseAltitude && PosY <= ReleaseAltitude)
 1267                {
 1268                    PosY = ReleaseAltitude;
 1269                    HasArrived = true;
 1270                }
 73771            }
 72            else
 073            {
 74                // 空基投放:自由落体
 075                PosY -= 9.81f * deltaTime;
 076                PosX += (TargetX - PosX) * 0.1f;
 077                PosZ += (TargetZ - PosZ) * 0.1f;
 78
 079                if (PosY <= ReleaseAltitude)
 080                {
 081                    PosY = ReleaseAltitude;
 082                    HasArrived = true;
 083                }
 084            }
 73785        }
 86    }
 87}