using System.Diagnostics; using Microsoft.Msagl.Core.Geometry; namespace Microsoft.Msagl.Routing.Rectilinear { internal class VertexEntry { /// /// A class that records an entry from a specific direction for a vertex. /// /// Vertex that this VertexEntry enters /// The previous VertexEntry along this path; null for a path source /// Length of the path up to this vertex /// Number of bends in the path up to this vertex /// Cost of the path up to this vertex internal VertexEntry(VisibilityVertexRectilinear vertex, VertexEntry prevEntry, double length, int numberOfBends, double cost) { this.Vertex = vertex; this.Direction = (prevEntry != null) ? CompassVector.PureDirectionFromPointToPoint(prevEntry.Vertex.Point, vertex.Point) : Directions. None; this.ResetEntry(prevEntry, length, numberOfBends, cost); } internal void ResetEntry(VertexEntry prevEntry, double length, int numberOfBends, double cost) { // A new prevEntry using the same previous vertex but a different entry to that vertex is valid here; // e.g. we could have prevEntry from S, which in turn had a prevEntry from E, replaced by prevEntry from // S which has a prevEntry from S. #if DEBUG if (this.PreviousEntry != null) { Debug.Assert(this.PreviousEntry.Vertex == prevEntry.Vertex, "Inconsistent prevEntry vertex"); Debug.Assert(this.PreviousEntry.Direction != prevEntry.Direction, "Duplicate prevEntry direction"); Debug.Assert(this.Direction == CompassVector.PureDirectionFromPointToPoint(this.PreviousEntry.Vertex.Point, this.Vertex.Point), "Inconsistent entryDir"); } #endif // DEBUG this.PreviousEntry = prevEntry; this.Length = length; this.NumberOfBends = numberOfBends; this.Cost = cost; } /// /// Cost of the path up to this vertex /// internal double Cost { get; private set; } /// /// The vertex that this VertexEntry enters /// internal VisibilityVertexRectilinear Vertex { get; private set; } /// /// The vertex that this VertexEntry is entered from /// internal VisibilityVertexRectilinear PreviousVertex { get { return (this.PreviousEntry == null) ? null : this.PreviousEntry.Vertex; } } /// /// The direction of entry to the vertex for this path (i.e. the direction from PreviousVertex to this.Vertex). /// internal Directions Direction { get; private set; } /// /// The length of the path up to this vertex /// internal double Length { get; private set; } /// /// The number of bends in the path up to this vertex /// internal int NumberOfBends { get; private set; } /// /// The previous VertexEntry along this path; null for a path source. /// internal VertexEntry PreviousEntry { get; private set; } /// /// Indicates whether we are allowing further entries into this vertex from this direction. /// internal bool IsClosed { get; set; } /// /// public override string ToString() { return this.Vertex.Point + " " + this.Direction + " " + this.IsClosed + " " + this.Cost; } } }