public IEnumerable <SegmentProxy> GetSegments(IBox box) { foreach (BoxTree <SegmentProxy> .TileEntry tileEntry in _boxTree.Search(box)) { yield return(tileEntry.Value); } }
public Vertex GetNearestVertex([NotNull] Vertex searchVertex) { var searchBox = new Box(new Pnt2D(searchVertex.X - _tolerance, searchVertex.Y - _tolerance), new Pnt2D(searchVertex.X + _tolerance, searchVertex.X + _tolerance)); double minDistanceSqr = double.MaxValue; Vertex nearestVertex = null; foreach (BoxTree <Vertex> .TileEntry tileEntry in _boxTree.Search(searchBox)) { Vertex candidate = tileEntry.Value; double distanceSqr = GetDistanceSqr(searchVertex, candidate); if (distanceSqr > _toleranceSquared) { // outside tolerance, ignore continue; } if (distanceSqr < minDistanceSqr) { // nearest so far nearestVertex = candidate; minDistanceSqr = distanceSqr; } } return(nearestVertex); }
private List <BoxTree <CachedRow> .TileEntry> SearchList( [NotNull] IGeometry searchGeometry, int tableIndex) { Assert.ArgumentNotNull(searchGeometry, nameof(searchGeometry)); IBox searchGeometryBox = QaGeometryUtils.CreateBox(searchGeometry, GetXYTolerance(tableIndex)); BoxTree <CachedRow> boxTree = _rowBoxTrees[tableIndex]; if (_currentRowNeighbors == null) { _currentRowNeighbors = new BoxSelection[_cachedTableCount]; } BoxSelection currentRowBoxSelection = _currentRowNeighbors[tableIndex]; if (currentRowBoxSelection == null) { currentRowBoxSelection = CreateCurrentRowToleranceSelection(tableIndex); _currentRowNeighbors[tableIndex] = currentRowBoxSelection; } IBox searchBox = null; var isWithin = false; if (currentRowBoxSelection != null) { isWithin = currentRowBoxSelection.Box.Contains(searchGeometryBox); } if (!isWithin) { searchBox = searchGeometryBox; } else if (currentRowBoxSelection.Selection == null) { searchBox = currentRowBoxSelection.Box; } List <BoxTree <CachedRow> .TileEntry> tileEntries; if (searchBox != null) { tileEntries = new List <BoxTree <CachedRow> .TileEntry>(); foreach ( BoxTree <CachedRow> .TileEntry tileEntry in boxTree.Search(searchBox)) { tileEntries.Add(tileEntry); } if (isWithin) { currentRowBoxSelection.Selection = tileEntries; } } else { tileEntries = currentRowBoxSelection.Selection; } if (!isWithin || searchGeometryBox.Contains(currentRowBoxSelection.Box)) { return(tileEntries); } // drop non intersection lines Assert.NotNull(tileEntries, "tileEntries"); var reducedList = new List <BoxTree <CachedRow> .TileEntry>(tileEntries.Count); foreach (BoxTree <CachedRow> .TileEntry tileEntry in tileEntries) { if (tileEntry.Box.Intersects(searchGeometryBox)) { reducedList.Add(tileEntry); } } return(reducedList); }