protected IEnumerable <HeightSegmentPair> GetHeightSegmentPairs( IEnumerable <SegmentProxy> segments) { List <HeightSegment> horizontalSegments = ReadHorizontalSegments(segments); horizontalSegments.Sort(HeightSegment.CompareHeight); List <HeightSegment> sortedHorizontalSegments = horizontalSegments; for (var baseIndex = 0; baseIndex < sortedHorizontalSegments.Count; baseIndex++) { HeightSegment baseSegment = sortedHorizontalSegments[baseIndex]; double baseHeight = baseSegment.Height; double maxSearchHeight = baseHeight + _nearHeight; for (int nearIndex = baseIndex + 1; nearIndex < sortedHorizontalSegments.Count; nearIndex++) { HeightSegment candidate = sortedHorizontalSegments[nearIndex]; if (candidate.Height < maxSearchHeight) { yield return(new HeightSegmentPair(baseSegment, candidate)); } else { break; } } } }
public HeightSegmentPair([NotNull] HeightSegment baseSegment, [NotNull] HeightSegment nearSegment) { _baseSegment = baseSegment; _nearSegment = nearSegment; HeightDifference = Math.Abs(baseSegment.Height - nearSegment.Height); }
public static int CompareHeight(HeightSegment x, HeightSegment y) { return(x._height.CompareTo(y._height)); }