예제 #1
0
        void PerformAllOperations()
        {
            foreach (Interval <int> range in _ranges)
            {
                // Perform on original data.
                for (int i = range.Start; i <= range.End; ++i)
                {
                    _originalData[i] = _operation(_originalData[i]);
                }

                // Add to list.
                _list.AddOperation(_operation, range);
            }
        }
        /// <summary>
        /// Removes a key point with the given index.
        /// </summary>
        /// <param name = "index">The index of the key point to remove.</param>
        public override void Remove(int index)
        {
            KeyPoint remove = _data[index];

            // Update distance for all data following this index.
            TMath excessDistance = _zero;

            if (index != _data.Count - 1)
            {
                KeyPoint next = _data[index + 1];

                // Find excess distance
                excessDistance = DistanceBetween(remove.Value, next.Value);
                if (index != 0)
                {
                    // Substract new distance from previous point.
                    TMath newDistance = DistanceBetween(_data[index - 1].Value, next.Value);
                    excessDistance = Operator <TMath> .Subtract(excessDistance, newDistance);
                }

                // Update by adding a pending operation to the range of all following data.
                _data.AddOperation(
                    d =>
                {
                    d.Position = Operator <TMath> .Subtract(d.Position, excessDistance);
                    return(d);
                },
                    new Interval <int>(index + 1, _data.Count - 1));
            }

            _data.RemoveAt(index);

            // Update data range.
            if (_data.Count == 0)
            {
                _dataRange = null;
            }
            else
            {
                _dataRange = new Interval <TMath>(
                    _zero,
                    Operator <TMath> .Subtract(DataRange.End, excessDistance));
            }
        }