修改楼梯边界膨胀的bug
This commit is contained in:
parent
8b5e2baf23
commit
2464f17092
@ -872,7 +872,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
public struct HeightLayer
|
||||
{
|
||||
/// <summary>
|
||||
/// 该层的Z坐标(米)
|
||||
/// 该层的Z坐标(模型单位)
|
||||
/// </summary>
|
||||
public double Z { get; set; }
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user