/// <summary> /// Checks if the endpoints are shared, meaning that their vertex index /// is the same as one in another segment. /// </summary> /// <remarks> /// This does not check based on position. It functions purely off of /// the information from a <see cref="VertexAllocator"/> from which /// this segment had its vertex index created from. /// </remarks> /// <param name="segment">The other segment to check against.</param> /// <returns>True if one of the endpoints is shared, false if not. /// </returns> public bool SharesAnyEndpoints(BspSegment segment) { return(StartIndex == segment.StartIndex || StartIndex == segment.EndIndex || EndIndex == segment.StartIndex || EndIndex == segment.EndIndex); }
private BspSegment CreateNewSegment(BspVertex start, BspVertex end, int collinearIndex, IBspUsableLine line = null) { BspSegment seg = new BspSegment(start, end, collinearIndex, line); segments.Add(seg); return(seg); }
/// <summary> /// Performs a split on the segment at some time t (which should be in /// the normal range). /// </summary> /// <param name="seg">The segment to split.</param> /// <param name="t">The time to split at, which should be in (0, 1). It /// is an error for it to be equal to 0.0 or 1.0 as that would create /// a point for a segment (which is no longer a segment).</param> /// <returns>The two segments, where the first element is the segment /// from [start, middle], and the second segment element is from the /// [middle, end].</returns> public (BspSegment first, BspSegment second) Split(BspSegment seg, double t) { Debug.Assert(t > 0.0 && t < 1.0, "Trying to split BSP out of the (0.0, 1.0) range"); Vec2D middle = seg.FromTime(t); BspVertex middleVertex = vertexAllocator[middle]; BspSegment firstSeg = GetOrCreate(seg.StartVertex, middleVertex, seg.Line.Value); BspSegment secondSeg = GetOrCreate(middleVertex, seg.EndVertex, seg.Line.Value); return(firstSeg, secondSeg); }
private void PruneSegment(int currentIndex, int nextIndex) { BspSegment segment = segmentTable[currentIndex, nextIndex]; if (segment == null) { throw new NullReferenceException("Cannot prune a segment that doesn't exist"); } Debug.Assert(!PrunedSegments.Contains(segment), "Trying to prune a segment we already pruned"); PrunedSegments.Add(segment); RemoveFromAdjacencyList(currentIndex, nextIndex); }
/// <summary> /// Adds a new segment to be tracked by this table. /// </summary> /// <param name="segment">The segment to add. This should not already /// be in the table.</param> public void Add(BspSegment segment) { (int minIndex, int maxIndex) = segment.StartIndex.MinMax(segment.EndIndex); if (table.TryGetValue(minIndex, out VertexSegmentPairList vertexSegPairs)) { vertexSegPairs.Add(maxIndex, segment); return; } VertexSegmentPairList pairList = new VertexSegmentPairList(); pairList.Add(maxIndex, segment); table[minIndex] = pairList; }
internal bool TryGetSegIndex(int maxIndex, out BspSegment segment) { for (int i = 0; i < pairs.Count; i++) { (int vertexIndex, BspSegment seg) = pairs[i]; if (maxIndex == vertexIndex) { segment = seg; return(true); } } segment = default; return(false); }
/// <summary> /// Tries to get the value provided. Order of the indices does not have /// any effect on the result. /// </summary> /// <param name="firstVertexIndex">The first vertex index.</param> /// <param name="secondVertexIndex">The second vertex index.</param> /// <param name="segment">The segment to be set with the value if it /// does exist.</param> /// <returns>True if it does exist, false if not (and is unsafe to /// use the out value).</returns> public bool TryGetValue(int firstVertexIndex, int secondVertexIndex, out BspSegment segment) { (int minIndex, int maxIndex) = firstVertexIndex.MinMax(secondVertexIndex); if (table.TryGetValue(minIndex, out VertexSegmentPairList vertexSegPairs)) { if (vertexSegPairs.TryGetSegIndex(maxIndex, out BspSegment foundSeg)) { segment = foundSeg; return(true); } } segment = default; return(false); }
internal void Add(int maxIndex, BspSegment segment) { Debug.Assert(!Contains(maxIndex), "Trying to add the same vertex/seg pair twice"); pairs.Add((maxIndex, segment)); }