/// <nodoc/> public static Interval <T> CreateInterval(T lowerBound, T upperBound, IntervalBoundType lowerBoundType = IntervalBoundType.Closed, IntervalBoundType upperBoundType = IntervalBoundType.Closed) { Contract.Requires(!(lowerBoundType == IntervalBoundType.Unbounded && upperBoundType == IntervalBoundType.Unbounded) || lowerBound.CompareTo(upperBound) <= 0); return(new Interval <T>(lowerBound, upperBound, lowerBoundType, upperBoundType)); }
private Interval(T lowerBound, T upperBound, IntervalBoundType lowerBoundType, IntervalBoundType upperBoundType) { LowerBound = lowerBound; UpperBound = upperBound; LowerBoundType = lowerBoundType; UpperBoundType = upperBoundType; }
/// <summary> /// Creates an interval of the form {-infinite, T} /// </summary> public static Interval <T> CreateIntervalWithNoLowerBound(T upperBound, IntervalBoundType upperBoundBoundType = IntervalBoundType.Closed) { return(new Interval <T>(default(T), upperBound, IntervalBoundType.Unbounded, upperBoundBoundType)); }
/// <summary> /// Creates an interval of the form {T, +infinite} /// </summary> public static Interval <T> CreateIntervalWithNoUpperBound(T lowerBound, IntervalBoundType lowerBoundBoundType = IntervalBoundType.Closed) { return(new Interval <T>(lowerBound, default(T), lowerBoundBoundType, IntervalBoundType.Unbounded)); }
/// <summary> /// Creates a new bound with the specified value and type. /// </summary> public static IntervalBound <A> Create <A>(A bound, IntervalBoundType type) { return(new IntervalBound <A>(bound, type)); }
/// <summary> /// Method for creating an interval based on inputted values /// </summary> /// <param name="intervalType"></param> /// <returns></returns> protected Interval MakeInterval(IntervalType intervalType) { IntervalBoundType leftBoundType = new IntervalBoundType(); IntervalBoundType rightBoundType = new IntervalBoundType(); int leftBound = 0; int rightBound = 0; bool isint = true; float leftDoubleBound = 0; float rightDoubleBound = 0; if (!RadioMinusInfinity.Checked) { if (RadioLeftBoundRound.Checked) { leftBoundType = IntervalBoundType.Round; } else { leftBoundType = IntervalBoundType.Sharp; } switch (intervalType) { case IntervalType.Long: try { leftBound = Convert.ToInt32(TextBoxLeftBound.Text); } catch { throw new ArgumentOutOfRangeException(); } break; case IntervalType.Float: try { isint = false; leftDoubleBound = (float)Convert.ToDouble(TextBoxLeftBound.Text); } catch { throw new ArgumentOutOfRangeException(); } break; default: throw new Exception("Switch branch not implemented"); } } else { leftBoundType = IntervalBoundType.Infinity; } if (!RadioPlusInfinity.Checked) { if (RadioRightBoundRound.Checked) { rightBoundType = IntervalBoundType.Round; } else { rightBoundType = IntervalBoundType.Sharp; } switch (intervalType) { case IntervalType.Long: try { rightBound = Convert.ToInt32(TextBoxRightBound.Text); } catch { throw new ArgumentOutOfRangeException(); } break; case IntervalType.Float: try { isint = false; rightDoubleBound = (float)Convert.ToDouble(TextBoxRightBound.Text); } catch { throw new ArgumentOutOfRangeException(); } break; default: throw new Exception("Switch branch not implemented"); } } else { rightBoundType = IntervalBoundType.Infinity; } Interval interval; if (isint) { interval = new Interval(IntervalType.Long); interval.lowerBound = leftBound; interval.upperBound = rightBound; interval.lowerBoundType = leftBoundType; interval.upperBoundType = rightBoundType; //interval = new Interval(leftBound, rightBound, leftBoundType, rightBoundType); } else { interval = new Interval(IntervalType.Float); interval.lowerBoundFl = leftDoubleBound; interval.upperBoundFl = rightDoubleBound; interval.lowerBoundType = leftBoundType; interval.upperBoundType = rightBoundType; //interval = new Interval(leftDoubleBound, rightDoubleBound, leftBoundType, rightBoundType); } return interval; }