You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project/Src/command_center/web-command-center/test/test-path-segment-fix.js

139 lines
4.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 测试路径段检测修复效果
const { isPathSegmentSafe, aStarPlanningImproved, isPointInAnyThreatZone } = require('./backend/src/routes/pathPlanning.js');
console.log('=== 路径段检测修复验证测试 ===\n');
// 测试威胁区 - 使用实际的多边形威胁区
const testThreatZones = [
{
id: 2,
type: "radar",
level: "high",
geometry_type: "polygon",
geometry_data: {
type: "polygon",
path: [ // 这个多边形覆盖了从起点到终点的直线路径
[112.998212, 28.105175],
[113.053664, 28.111999],
[113.048066, 28.08616],
[112.979811, 28.083835],
[112.968328, 28.097401]
]
},
description: "多边形威胁区测试"
},
{
id: 1,
type: "aircraft",
level: "medium",
geometry_type: "circle",
geometry_data: {
type: "circle",
center: [113.019349, 28.153602],
radius: 3790.243
},
description: "圆形威胁区测试"
}
];
// 测试路径段 - 这些路径段应该穿过多边形威胁区
const testPathSegments = [
{
name: "直接穿过多边形威胁区",
start: { lng: 112.969693, lat: 28.122363 },
end: { lng: 113.031207, lat: 28.067036 },
expectedSafe: false
},
{
name: "从多边形内部到外部",
start: { lng: 113.010000, lat: 28.090000 }, // 多边形内
end: { lng: 113.070000, lat: 28.070000 }, // 多边形外
expectedSafe: false
},
{
name: "完全在多边形外部",
start: { lng: 112.950000, lat: 28.120000 },
end: { lng: 112.960000, lat: 28.130000 },
expectedSafe: true
},
{
name: "擦边通过多边形",
start: { lng: 112.990000, lat: 28.110000 },
end: { lng: 113.000000, lat: 28.105000 },
expectedSafe: false // 可能擦边通过
}
];
console.log('=== 测试路径段检测功能 ===');
for (const segment of testPathSegments) {
console.log(`\n测试: ${segment.name}`);
console.log(`起点: (${segment.start.lng}, ${segment.start.lat})`);
console.log(`终点: (${segment.end.lng}, ${segment.end.lat})`);
const result = isPathSegmentSafe(
segment.start.lng, segment.start.lat,
segment.end.lng, segment.end.lat,
testThreatZones,
false
);
const status = result.safe === segment.expectedSafe ? '✓ 正确' : '✗ 需要检查';
console.log(`${status}: 预期安全=${segment.expectedSafe}, 实际安全=${result.safe}`);
if (!result.safe) {
console.log(` ❌ 穿过威胁区: ${result.threatZoneIds.join(', ')}`);
if (result.sampledAt) {
console.log(` 🔍 检测位置: 第${result.sampledAt.i}/${result.sampledAt.total}个采样点`);
console.log(` 📍 威胁点坐标: (${result.sampledAt.point[0].toFixed(6)}, ${result.sampledAt.point[1].toFixed(6)})`);
}
} else {
console.log(` ✅ 路径安全,检查了${result.samplesChecked}个采样点`);
if (result.passedThreatZones.length > 0) {
console.log(` ⚠️ 允许通过威胁区: ${result.passedThreatZones.join(', ')}`);
}
}
}
console.log('\n=== 测试A*路径规划(模拟) ===');
console.log('注意这是简化测试实际A*算法会通过后端API调用\n');
// 测试A*路径规划的关键场景
const planningTest = {
start: { lng: 112.969693, lat: 28.122363, altitude: 100 },
end: { lng: 113.031207, lat: 28.067036, altitude: 100 }
};
console.log('路径规划测试场景:');
console.log(`起点: (${planningTest.start.lng}, ${planningTest.start.lat})`);
console.log(`终点: (${planningTest.end.lng}, ${planningTest.end.lat})`);
// 检查起点终点安全性
const startSafe = isPointInAnyThreatZone(planningTest.start.lng, planningTest.start.lat, testThreatZones);
const endSafe = isPointInAnyThreatZone(planningTest.end.lng, planningTest.end.lat, testThreatZones);
console.log(`起点安全性: ${startSafe.inThreat ? `❌ 在威胁区${startSafe.zoneId}` : '✅ 安全'}`);
console.log(`终点安全性: ${endSafe.inThreat ? `❌ 在威胁区${endSafe.zoneId}` : '✅ 安全'}`);
// 检查直线路径
const directPath = isPathSegmentSafe(
planningTest.start.lng, planningTest.start.lat,
planningTest.end.lng, planningTest.end.lat,
testThreatZones, false
);
console.log(`直线路径安全性: ${directPath.safe ? '✅ 安全' : `❌ 穿过威胁区${directPath.threatZoneIds.join(',')}`}`);
if (!directPath.safe) {
console.log('🚀 由于直线路径不安全A*算法将启动寻找绕行路径');
console.log(' 预期结果:算法应该找到避开多边形威胁区的安全路径');
console.log(' 修复前:可能会错误地返回直线路径');
console.log(' 修复后:应该正确检测并避开威胁区');
}
console.log('\n=== 测试完成 ===');
console.log('如果所有测试都显示"✓ 正确",说明路径段检测修复成功!');
console.log('现在可以启动后端服务器测试完整的路径规划功能。');