using System;
namespace MultiWheelC.TrajectoryPlanning.CoarsePath.Search;
///
/// Hybrid A* 闭集使用的离散状态键。
/// 位置使用地图行列索引;航向、行驶方向和曲率等级共同保留车辆运动学状态,避免把同一栅格中的不同可达姿态错误合并。
///
public sealed class HybridAStarNodeKey : IEquatable
{
///
/// 创建一个离散 Hybrid A* 状态键。
/// 参数:row、column 为零开始的地图行列;headingIndex 为航向桶;direction 为末段行驶方向;curvatureLevelIndex 为末段曲率等级。
///
public HybridAStarNodeKey(int row, int column, int headingIndex, TravelDirection direction, int curvatureLevelIndex)
{
Row = row;
Column = column;
HeadingIndex = headingIndex;
Direction = direction;
CurvatureLevelIndex = curvatureLevelIndex;
}
/// 车辆中心所在的零开始地图行索引。
public int Row { get; }
/// 车辆中心所在的零开始地图列索引。
public int Column { get; }
/// 与 含义相同的列索引别名。
public int Col { get { return Column; } }
/// 根据配置航向分辨率量化后的航向桶索引。
public int HeadingIndex { get; }
/// 到达当前节点的最后一段行驶方向。
public TravelDirection Direction { get; }
/// 到达当前节点的最后一段曲率等级索引。
public int CurvatureLevelIndex { get; }
/// 判断另一个键是否表示完全相同的离散搜索状态。
public bool Equals(HybridAStarNodeKey other)
{
return other != null && Row == other.Row && Column == other.Column && HeadingIndex == other.HeadingIndex &&
Direction == other.Direction && CurvatureLevelIndex == other.CurvatureLevelIndex;
}
/// 判断另一个对象是否表示完全相同的离散搜索状态。
public override bool Equals(object obj)
{
return Equals(obj as HybridAStarNodeKey);
}
/// 返回用于闭集字典的稳定哈希值。
public override int GetHashCode()
{
unchecked
{
int hashCode = Row;
hashCode = hashCode * 397 ^ Column;
hashCode = hashCode * 397 ^ HeadingIndex;
hashCode = hashCode * 397 ^ (int)Direction;
return hashCode * 397 ^ CurvatureLevelIndex;
}
}
}