/// <summary> /// Remove the currently-cached curve so it will be recalculated next time it is needed. /// </summary> private void BecomeDirty() { lock (_curveLock) { _currentCurve = null; } }
/// <summary> /// Remove a point object by index from this curve. /// </summary> /// <param name="index">Index of the point to remove.</param> public void RemoveAt(int index) { lock (_curveLock) { _points.RemoveAt(index); _currentCurve = null; } }
/// <summary> /// Add a new point to this curve. It starts at a default location. When it is moved, this structure will be /// notified to update its calculated curve. /// </summary> /// <returns>A new TControl from the point factory, which is now part of this curve. It is appended to the /// internal point list, so it has the (new) highest index.</returns> public TControl NewPoint() { lock (_curveLock) { TControl p = _pointFactory.NewPoint(BecomeDirty); _points.Add(p); _currentCurve = null; return(p); } }
/// <summary> /// Find a specific point object and remove it from this curve. /// </summary> /// <param name="p">Object to remove.</param> /// <returns>Whether this object was found and removed.</returns> public bool RemovePoint(TControl p) { lock (_curveLock) { bool ret = _points.Remove(p); if (ret) { _currentCurve = null; } return(ret); } }
/// <summary> /// Get an ICurve{TOut} corresponding to the current location of the points in this curve. /// </summary> /// <returns>An ICurve{TOut} from _curveFactory, from the current points.</returns> public DerivableFunction <double, TOut> CurrentCurve() { lock (_curveLock) { // This uses the lazily-evaluated null-coalescence operator to either return the curve we have // or, if we don't have one, calculate a new one, save it, and then return that. // We save the curves we calculate to avoid the (potentially expensive) recalculation every time // a single value is requested, but recalculate whenever we did not have one (either because it // was never calculated before, or because we dropped it since a point moved and we need to // recalculate the curve next time something wants it - which is right now). return(_currentCurve ?? (_currentCurve = _curveFactory.NewCurve(_points))); } }