public static void OnInserted(IDistanceCounterCollection distances, ILineSizeHost linesHost, int insertAt, int count)
        {
            distances.Insert(insertAt, count);
            int to = insertAt + count - 1;
            int repeatSizeCount;

            // Set line sizes
            for (int index = insertAt; index <= to; index++)
            {
                double size = linesHost.GetSize(index, out repeatSizeCount);
                if (size != distances.DefaultDistance)
                {
                    int rangeTo = GetRangeToHelper(index, to, repeatSizeCount);
                    distances.SetRange(index, rangeTo, size);
                    index = rangeTo;
                }
            }

            // Also check for hidden rows and reset line sizes for them.
            for (int index = insertAt; index <= to; index++)
            {
                bool hide = linesHost.GetHidden(index, out repeatSizeCount);
                if (hide)
                {
                    int rangeTo = GetRangeToHelper(index, to, repeatSizeCount);
                    distances.SetRange(index, rangeTo, 0.0);
                    index = rangeTo;
                }
            }
        }
        public static double GetTotal(ILineSizeHost lines, int from, int to)
        {
            int    repeatCount;
            int    index = from;
            double total = 0;

            while (index <= to)
            {
                double w = lines.GetSize(index, out repeatCount);
                repeatCount = Math.Min(to - index + 1, repeatCount);
                total      += w * repeatCount;
                index      += repeatCount;
            }

            return(total);
        }
        public static void DistancesLineSizeChanged(IDistanceCounterCollection distances, ILineSizeHost linesHost, int from, int to)
        {
            var ndh = linesHost as INestedDistancesHost;

            for (int n = from; n <= to; n++)
            {
                if (ndh == null || ndh.GetDistances(n) == null)
                {
                    int    repeatSizeCount;
                    double size    = linesHost.GetSize(n, out repeatSizeCount);
                    int    rangeTo = GetRangeToHelper(n, to, repeatSizeCount);
                    distances.SetRange(n, rangeTo, size);
                    n = rangeTo;
                }
                else
                {
                    distances.SetNestedDistances(n, ndh.GetDistances(n));
                }
            }
        }
        public static double[] GetRange(ILineSizeHost lines, int from, int to)
        {
            int count  = to - from + 1;
            var values = new double[count];

            int repeatCount;
            int index = from;
            int n     = 0;

            while (index <= to)
            {
                double w = lines.GetSize(index, out repeatCount);
                repeatCount = Math.Min(to - index + 1, repeatCount);
                for (int i = 0; i < repeatCount; i++)
                {
                    values[n++] = w;
                }
                index += repeatCount;
            }

            return(values);
        }