private void SetStateLoadedInfo(List <BspSegment> segments) { // We're just picking a random vertex, and taking some random segment that // comes out of that vertex. int randomVertexIndex = VertexMap.Keys.First(); ConvexTraversalPoint randomLinePoint = VertexMap[randomVertexIndex].First(); BspSegment startSegment = randomLinePoint.Segment; States.CurrentEndpoint = randomLinePoint.Endpoint; States.StartSegment = startSegment; States.CurrentSegment = startSegment; States.TotalSegs = segments.Count; }
private void AddSegmentEndpoint(BspSegment segment, int index, Endpoint endpoint) { ConvexTraversalPoint linePoint = new ConvexTraversalPoint(segment, endpoint); if (VertexMap.TryGetValue(index, out List <ConvexTraversalPoint> linePoints)) { linePoints.Add(linePoint); VertexTracker.Track(linePoints.Count); } else { List <ConvexTraversalPoint> newLinePoints = new List <ConvexTraversalPoint> { linePoint }; VertexMap.Add(index, newLinePoints); VertexTracker.Track(newLinePoints.Count); } }
private bool IsProperlyConnectedEndpoint(BspSegment segment, Endpoint endpoint) { if (Traversal.Empty()) { return(true); } ConvexTraversalPoint lastPoint = Traversal.Last(); BspSegment lastSeg = lastPoint.Segment; Endpoint lastEndpoint = lastPoint.Endpoint; if (ReferenceEquals(segment, lastSeg)) { Debug.Assert(false, "Trying to add the same segment twice"); return(false); } // Because our traversal uses the first endpoint we reached, that // means the last segment's opposite endpoint should match this // segment's current endpoint. Graphically, this means: // // LastEndpoint Endpoint // o-----------o------------o // LastSeg Segment // // Notice that the opposite endpoint of LastEndpoint is equal to // the middle vertex labeled Endpoint. This is what we want to make // sure are equal since it is not a valid traversal if they do not // match. if (segment.IndexFrom(endpoint) != lastSeg.OppositeIndex(lastEndpoint)) { Debug.Assert(false, "Expect a tail-to-head connection"); return(false); } return(true); }