using System;
using System.Drawing;
namespace AGVNavigationCore.PathFinding
{
///
/// A* 알고리즘에서 사용하는 경로 노드
///
public class PathNode
{
///
/// 노드 ID
///
public string NodeId { get; set; }
///
/// 노드 위치
///
public Point Position { get; set; }
///
/// 시작점으로부터의 실제 거리 (G cost)
///
public float GCost { get; set; }
///
/// 목적지까지의 추정 거리 (H cost - 휴리스틱)
///
public float HCost { get; set; }
///
/// 총 비용 (F cost = G cost + H cost)
///
public float FCost => GCost + HCost;
///
/// 부모 노드 (경로 추적용)
///
public PathNode Parent { get; set; }
///
/// 연결된 노드 ID 목록
///
public System.Collections.Generic.List ConnectedNodes { get; set; }
///
/// 생성자
///
/// 노드 ID
/// 위치
public PathNode(string nodeId, Point position)
{
NodeId = nodeId;
Position = position;
GCost = 0;
HCost = 0;
Parent = null;
ConnectedNodes = new System.Collections.Generic.List();
}
///
/// 다른 노드까지의 유클리드 거리 계산
///
/// 대상 노드
/// 거리
public float DistanceTo(PathNode other)
{
float dx = Position.X - other.Position.X;
float dy = Position.Y - other.Position.Y;
return (float)Math.Sqrt(dx * dx + dy * dy);
}
///
/// 문자열 표현
///
public override string ToString()
{
return $"{NodeId} - F:{FCost:F1} G:{GCost:F1} H:{HCost:F1}";
}
///
/// 같음 비교 (NodeId 기준)
///
public override bool Equals(object obj)
{
if (obj is PathNode other)
{
return NodeId == other.NodeId;
}
return false;
}
///
/// 해시코드 (NodeId 기준)
///
public override int GetHashCode()
{
return NodeId?.GetHashCode() ?? 0;
}
}
}