CounterDroneBackend/test/unit/CounterDrone.Core.Tests/MunitionEntityTests.cs
tian 0ed714a730 refactor: 抛物线运动学前向计算 — 移除回退/反算,统一用 ParabolicPosition
Kinematics:
- CalculateLaunchAngle/ParabolicTimeOfFlight/ParabolicShellTime: 移除静默钳位和 45° 回退,输入无效直接抛异常
- 新增 ComputeParabolicRange(v₀,θ,Δy) → (射程,飞行时间) — 正问题
- 新增 ParabolicApex(v₀,θ) → (顶点高度,顶点时间)
- ParabolicShellTime 改为委托,不重复实现

MunitionEntity:
- launchAngle 必须由方案提供,不再反算
- _flightDuration 用 ComputeParabolicRange 正算
- 删除死代码 CommandFlyTo / 「到达投放点」路径

DefensePlanner:
- 地基用 InterceptCalculator 的 shellTime,不再用 ParabolicShellTime 反算

SimulationEngine:
- 删除空基「到达投放点」死代码

Tests: 240 通过 (KinematicsTests 38, DefensePlannerTests 36, SimulationEngineTests 12, MunitionEntityTests 3)
2026-06-17 10:45:56 +08:00

45 lines
1.9 KiB
C#

using CounterDrone.Core.Algorithms;
using CounterDrone.Core.Models;
using Xunit;
namespace CounterDrone.Core.Tests
{
public class MunitionEntityTests
{
// ═══════════════════════════════════════
// 抛物线运动学:方位角和位置的对应关系
// ═══════════════════════════════════════
[Fact]
public void Parabolic_45Deg_Azimuth0_MovesInZ()
{
// azimuth=0 → +Z方向, sin(0)=0→X, cos(0)=1→Z
float angle45 = 45f * (float)System.Math.PI / 180f;
var (x, y, z) = Kinematics.ParabolicPosition(0, 0, 0, angle45, 0, 100, 1f);
Assert.True(System.Math.Abs(x) < 0.1f, $"X={x:F1} ≈0");
Assert.True(System.Math.Abs(y - 65.8f) < 1f, $"Y={y:F1} ≈65.8");
Assert.True(System.Math.Abs(z - 70.7f) < 1f, $"Z={z:F1} ≈70.7");
}
[Fact]
public void Parabolic_30Deg_Azimuth90_MovesInX()
{
float angle30 = 30f * (float)System.Math.PI / 180f;
float az90 = 90f * (float)System.Math.PI / 180f;
var (x, y, z) = Kinematics.ParabolicPosition(0, 0, 0, angle30, az90, 100, 1f);
Assert.True(System.Math.Abs(x - 86.6f) < 1f, $"X={x:F1} ≈86.6");
Assert.True(System.Math.Abs(z) < 0.1f, $"Z={z:F1} ≈0");
}
[Fact]
public void Parabolic_60Deg_Azimuth270_MovesBackward()
{
float angle60 = 60f * (float)System.Math.PI / 180f;
float az270 = 270f * (float)System.Math.PI / 180f;
var (x, y, z) = Kinematics.ParabolicPosition(0, 0, 0, angle60, az270, 100, 1f);
Assert.True(System.Math.Abs(x + 50f) < 1f, $"X={x:F1} ≈-50");
Assert.True(System.Math.Abs(z) < 0.1f, $"Z={z:F1} ≈0");
}
}
}