/// <summary> /// If the value is below the interval, this will return -1, if it is above /// the interval this will return 1 and 0 otherwise. Note that the interval has a /// closed interval semantics, i.e. interval = [a,b]. /// WARNING: Never use this extension like this: 1.0.CompareTo(interval), since if the value is negative /// the sign (if there is one) will not be passed to the extension method leading to unexpected results. /// </summary> public static int CompareToInterval(this float @this, Interval <float> interval) { if (@this.BelowInterval(interval)) { return(-1); } return(@this.AboveInterval(interval) ? 1 : 0); }
/// <summary> /// Attempts to find an evaluator. The only Time this will return null is when /// the value x is within the XInterval of the composite evaluator but there is /// no evaluator within the interval that contains x. /// </summary> IEvaluator FindEvaluator(float x) { int evCount = Evaluators.Count; if (x.InInterval(XInterval)) { return(FindInternalEvaluator(x)); } if (x.AboveInterval(XInterval)) { return(Evaluators[evCount - 1]); } return(x.BelowInterval(XInterval) ? Evaluators[0] : null); }
KeyValuePair <IEvaluator, IEvaluator> FindLeftAndRightInterpolators(float x) { int evCount = Evaluators.Count; IEvaluator lev = null; IEvaluator rev = null; for (int i = 0; i < evCount - 1; i++) { lev = Evaluators[i]; rev = Evaluators[i + 1]; if (x.AboveInterval(lev.XInterval) && x.BelowInterval(rev.XInterval)) { break; } } return(new KeyValuePair <IEvaluator, IEvaluator>(lev, rev)); }
public void FloatAboveIntervalTests(float value, Interval <float> interval, bool expected) { Assert.That(value.AboveInterval(interval), Is.EqualTo(expected)); }