using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using TransportGame.Primitives; namespace TransportGame.Model.Road { /// /// Road node /// [XmlRoot("node")] public class RoadNode : IPositionable { /// /// Gets or sets a unique identifier for this node /// [XmlAttribute("id")] public int Id { get; set; } /// /// Gets or sets the X coordinate of the node /// [XmlAttribute("x")] public float X { get; set; } /// /// Gets or sets the Y coordinate of the node /// [XmlAttribute("y")] public float Y { get; set; } /// /// Gets or sets the adjacent articulation segment IDs /// [XmlArray("articulationSegments")] [XmlArrayItem("id")] public List ArticulationSegmentIds { get; set; } /// /// Gets or sets the adjacent articulation segment IDs /// [XmlArray("intersectionSegments")] [XmlArrayItem("id")] public List IntersectionSegmentIds { get; set; } /// /// Gets or sets the parent network /// [XmlIgnore] public RoadNetwork ParentNetwork { get; set; } /// /// Gets the adjacent articulation segments /// [XmlIgnore] public IEnumerable ArticulationSegments { get { return ArticulationSegmentIds.Select(id => ParentNetwork.ArticulationSegments[id]); } } /// /// Gets the adjacent segments /// [XmlIgnore] public IEnumerable Segments { get { return IntersectionSegmentIds.Select(id => ParentNetwork.ArticulationSegments[id]); } } /// /// Initializes the node /// public RoadNode() { ArticulationSegmentIds = new List(); IntersectionSegmentIds = new List(); } /// /// Gets or sets the position /// [XmlIgnore] public Vector2 Position { get { return new Vector2(X, Y); } set { X = value.X; Y = value.Y; } } public override string ToString() { return string.Format("(node id={0}, {1})", Id, Position); } } }