public int?FindPointIdx([NotNull] Pnt3D point, bool inXY, double tolerance = double.Epsilon, bool allowIndexing = true) { if (SpatialIndex == null && allowIndexing && SegmentCount > AllowIndexingThreshold) { SpatialIndex = SpatialHashSearcher <int> .CreateSpatialSearcher(this); } if (SpatialIndex != null) { foreach (int foundSegmentIdx in SpatialIndex.Search(point, tolerance)) { Line3D segment = this[foundSegmentIdx]; bool found = inXY ? segment.StartPoint.EqualsXY(point, tolerance) : segment.StartPoint.Equals(point, tolerance); if (found) { return(foundSegmentIdx); } } } else { for (var i = 0; i < SegmentCount; i++) { bool found = inXY ? _segments[i].StartPoint.EqualsXY(point, tolerance) : _segments[i].StartPoint.Equals(point, tolerance); if (found) { return(i); } } } bool isEndPoint = inXY ? EndPoint.EqualsXY(point, tolerance) : EndPoint.Equals(point, tolerance); if (isEndPoint) { return(PointCount - 1); } return(null); }
public IEnumerable <int> FindPointIndexes([NotNull] IPnt searchPoint, double tolerance = double.Epsilon, bool useSearchCircle = false, bool allowIndexing = true) { if (SpatialIndex == null && allowIndexing && PointCount > AllowIndexingThreshold) { SpatialIndex = SpatialHashSearcher <int> .CreateSpatialSearcher(this); } if (SpatialIndex != null) { // No need to add the tolerance to the search box, it is added by the index foreach (int foundPointIdx in SpatialIndex.Search( searchPoint.X, searchPoint.Y, searchPoint.X, searchPoint.Y, tolerance)) { T foundPoint = _points[foundPointIdx]; bool withinTolerance = IsWithinTolerance(foundPoint, searchPoint, tolerance, useSearchCircle); if (withinTolerance) { yield return(foundPointIdx); } } } else { for (var i = 0; i < PointCount; i++) { bool withinTolerance = IsWithinTolerance(_points[i], searchPoint, tolerance, useSearchCircle); if (withinTolerance) { yield return(i); } } } }
public IEnumerable <KeyValuePair <int, Line3D> > FindSegments( double xMin, double yMin, double xMax, double yMax, double tolerance, bool allowIndexing = true, Predicate <int> predicate = null) { if (SpatialIndex == null && allowIndexing && SegmentCount > AllowIndexingThreshold) { SpatialIndex = SpatialHashSearcher <int> .CreateSpatialSearcher(this); } if (SpatialIndex != null) { foreach (int index in SpatialIndex.Search( xMin, yMin, xMax, yMax, this, tolerance, predicate)) { Line3D segment = _segments[index]; if (segment.ExtentIntersectsXY(xMin, yMin, xMax, yMax, tolerance)) { yield return(new KeyValuePair <int, Line3D>(index, segment)); } } } else { for (int i = 0; i < SegmentCount; i++) { if (predicate != null && !predicate(i)) { continue; } Line3D segment = this[i]; if (segment.ExtentIntersectsXY(xMin, yMin, xMax, yMax, tolerance)) { yield return(new KeyValuePair <int, Line3D>(i, segment)); } } } }