/// <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));
            }
        }
Beispiel #2
0
        public void RemoveTest()
        {
            PerformAllOperations();

            Random rand = new Random();

            while (_originalData.Count > 0)
            {
                // Remove.
                int removeIndex = rand.Next(_originalData.Count);
                _originalData.RemoveAt(removeIndex);
                _list.RemoveAt(removeIndex);

                // Verify.
                for (int i = 0; i < _originalData.Count; ++i)
                {
                    Assert.Equal(_originalData[i], _list[i]);
                }
            }
        }