修改楼梯边界膨胀的bug

This commit is contained in:
tian 2025-10-10 21:19:13 +08:00
parent 8b5e2baf23
commit 2464f17092
2 changed files with 18 additions and 16 deletions

View File

@ -872,7 +872,7 @@ namespace NavisworksTransport.PathPlanning
public struct HeightLayer
{
/// <summary>
/// 该层的Z坐标
/// 该层的Z坐标模型单位
/// </summary>
public double Z { get; set; }

View File

@ -922,8 +922,8 @@ namespace NavisworksTransport.PathPlanning
}
else
{
// 3. 该层索引不存在(网格没有这一层)→ 距离为0相当于障碍物
distanceMap[x, y] = 0.0;
// 3. 该层索引不存在(网格没有这一层)→ 设置为-1不参与距离变换
distanceMap[x, y] = -1.0;
}
}
}
@ -945,13 +945,14 @@ namespace NavisworksTransport.PathPlanning
{
double minDist = double.MaxValue;
if (x > 0)
// 从邻居计算距离,跳过 < 0 的邻居(没有该层的网格)
if (x > 0 && distanceMap[x - 1, y] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x - 1, y] + 1.0);
if (y > 0)
if (y > 0 && distanceMap[x, y - 1] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x, y - 1] + 1.0);
if (x > 0 && y > 0)
if (x > 0 && y > 0 && distanceMap[x - 1, y - 1] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x - 1, y - 1] + SQRT2);
if (x > 0 && y < gridMap.Height - 1)
if (x > 0 && y < gridMap.Height - 1 && distanceMap[x - 1, y + 1] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x - 1, y + 1] + SQRT2);
if (minDist != double.MaxValue)
@ -965,17 +966,18 @@ namespace NavisworksTransport.PathPlanning
{
for (int y = gridMap.Height - 1; y >= 0; y--)
{
if (distanceMap[x, y] != 0.0)
if (distanceMap[x, y] > 0.0) // 排除边界(0)和没有该层(-1)
{
double minDist = distanceMap[x, y];
if (x < gridMap.Width - 1)
// 从邻居计算距离,跳过 < 0 的邻居(没有该层的网格)
if (x < gridMap.Width - 1 && distanceMap[x + 1, y] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x + 1, y] + 1.0);
if (y < gridMap.Height - 1)
if (y < gridMap.Height - 1 && distanceMap[x, y + 1] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x, y + 1] + 1.0);
if (x < gridMap.Width - 1 && y < gridMap.Height - 1)
if (x < gridMap.Width - 1 && y < gridMap.Height - 1 && distanceMap[x + 1, y + 1] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x + 1, y + 1] + SQRT2);
if (x < gridMap.Width - 1 && y > 0)
if (x < gridMap.Width - 1 && y > 0 && distanceMap[x + 1, y - 1] >= 0.0)
minDist = Math.Min(minDist, distanceMap[x + 1, y - 1] + SQRT2);
distanceMap[x, y] = minDist;
@ -999,12 +1001,12 @@ namespace NavisworksTransport.PathPlanning
if (layer.Type == CategoryAttributeManager.LogisticsElementType.)
continue;
// 膨胀条件:距离>0排除源点且距离<=半径
// 例如:半径=2 → 膨胀距离1和距离2的网格
// 半径=3 → 膨胀距离1、2、3的网格
// 膨胀条件:距离>=0包括边界且距离<半径
// 例如:半径=2 → 膨胀距离0、1的网格总共2格
// 半径=3 → 膨胀距离0、1、2的网格总共3格
bool shouldInflate = false;
if (distanceMap[x, y] > 0.0 && distanceMap[x, y] <= inflationRadius)
if (distanceMap[x, y] >= 0.0 && distanceMap[x, y] < inflationRadius)
{
shouldInflate = true;
}