void Merge(DistanceLineCounterEntry entry, bool checkPrevious) { DistanceLineCounterSource value = entry.Value; DistanceLineCounterEntry previousEntry = null; if (checkPrevious) { previousEntry = rbTree.GetPreviousEntry(entry); } DistanceLineCounterEntry nextEntry = rbTree.GetNextEntry(entry); bool dirty = false; if (previousEntry != null && (previousEntry.Value).SingleLineDistance == value.SingleLineDistance) { value.LineCount += (previousEntry.Value).LineCount; //previousEntry.InvalidateCounterBottomUp(true); rbTree.Remove(previousEntry); dirty = true; } if (nextEntry != null && (nextEntry.Value).SingleLineDistance == value.SingleLineDistance) { value.LineCount += (nextEntry.Value).LineCount; //nextEntry.InvalidateCounterBottomUp(true); rbTree.Remove(nextEntry); dirty = true; } if (dirty) { entry.InvalidateCounterBottomUp(true); } }
int _IndexOfCumulatedDistance(double cumulatedDistance) { if (InternalCount == 0) { return((int)Math.Floor(cumulatedDistance / DefaultDistance)); } int delta = 0; double internalTotalDistance = InternalTotalDistance - this.paddingDistance; if (cumulatedDistance >= internalTotalDistance) { delta = (int)Math.Floor((cumulatedDistance - internalTotalDistance) / DefaultDistance); cumulatedDistance = internalTotalDistance; return(InternalCount + delta); } var searchPosition = new DistanceLineCounter(cumulatedDistance, 0); DistanceLineCounterEntry rbEntry = rbTree.GetEntryAtCounterPosition(searchPosition, DistanceLineCounterKind.Distance, false); DistanceLineCounterSource rbValue = rbEntry.Value; DistanceLineCounter rbEntryPosition = rbEntry.GetCounterPosition(); if (rbValue.SingleLineDistance > 0) { delta = (int)Math.Floor((cumulatedDistance - rbEntryPosition.Distance) / rbValue.SingleLineDistance); } return(rbEntryPosition.LineCount + delta); }