< Summary

Information
Class: CounterDrone.Core.Algorithms.GaussianPuffDispersion
Assembly: CounterDrone.Core
File(s): C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Algorithms\GaussianPuffDispersion.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_Center()100%11100%
get_Radius()100%11100%
get_CoreDensity()100%11100%
get_EffectiveRadius()100%11100%
get_Particles()100%11100%
get_IsDissipated()100%11100%
Initialize(...)100%11100%
Tick(...)100%88100%

File(s)

C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Algorithms\GaussianPuffDispersion.cs

#LineLine coverage
 1using System;
 2using CounterDrone.Core.Models;
 3
 4namespace CounterDrone.Core.Algorithms
 5{
 6    /// <summary>高斯烟团扩散模型 — 简化实现</summary>
 7    public class GaussianPuffDispersion : ICloudDispersionModel
 8    {
 199        private AmmunitionSpec _ammo = null!;
 10        private float _elapsed;
 11        private float _currentRadius;
 12        private Vector3 _center;
 13        private Vector3 _windVelocity;
 14
 218615        public Vector3 Center => _center;
 36716        public float Radius => _currentRadius;
 78517        public float CoreDensity { get; private set; }
 36418        public float EffectiveRadius => _currentRadius; // 简化:有效半径 = 物理半径
 112819        public ParticleParams Particles { get; } = new();
 112220        public bool IsDissipated { get; private set; }
 21
 22        public void Initialize(AmmunitionSpec ammo, CombatScene env, Vector3 releasePos, float releaseTime)
 1823        {
 1824            _ammo = ammo;
 1825            _elapsed = 0f;
 1826            _currentRadius = (float)ammo.InitialRadius;
 1827            _center = releasePos;
 1828            CoreDensity = (float)ammo.CoreDensity;
 1829            IsDissipated = false;
 30
 31            // 风速 → 速度矢量
 1832            var (vx, vy, vz) = Kinematics.WindToVector((WindDirection)env.WindDirection, (float)env.WindSpeed);
 1833            _windVelocity = new Algorithms.Vector3(vx, vy, vz);
 1834        }
 35
 36        public void Tick(float deltaTime, float windSpeed, WindDirection windDir)
 37037        {
 37038            if (IsDissipated) return;
 39
 37040            _elapsed += deltaTime;
 41
 42            // 更新风速(允许动态变化)
 37043            var (vx, vy, vz) = Kinematics.WindToVector(windDir, windSpeed);
 37044            _windVelocity = new Algorithms.Vector3(vx, vy, vz);
 45
 46            // 半径膨胀:初始半径 + 扩散速率 × 时间
 47            // 加入大气稳定度因子(简化:1.0)
 37048            var dispersionRate = (float)(_ammo.DispersionRateBase * 1.0f);
 37049            _currentRadius = (float)_ammo.InitialRadius + dispersionRate * _elapsed;
 50
 51            // 中心随风漂移
 37052            _center += _windVelocity * deltaTime;
 53
 54            // 密度衰减:核心密度 × (初始半径 / 当前半径)³
 37055            if (_currentRadius > 0.001f)
 37056            {
 37057                var volumeRatio = (float)System.Math.Pow((float)_ammo.InitialRadius / _currentRadius, 3);
 37058                CoreDensity = (float)_ammo.CoreDensity * volumeRatio;
 37059            }
 60
 61            // 更新粒子参数
 37062            Particles.Opacity = System.Math.Max(0.1f, CoreDensity / (float)_ammo.CoreDensity);
 37063            Particles.SizeMultiplier = _currentRadius / (float)_ammo.InitialRadius;
 64
 65            // 消散条件
 37066            if (_elapsed >= (float)_ammo.MaxDuration || _currentRadius >= (float)_ammo.MaxRadius)
 367            {
 368                IsDissipated = true;
 369                Particles.Opacity = 0f;
 370            }
 37071        }
 72    }
 73}