public override bool Validating(object value) { T newvalue; try { newvalue = CastValue <T>(value); } catch { return(false); } if (Min.CompareTo(default(T)) > 0) { if (newvalue.CompareTo(Min) < 0) { return(false); } } if (Max.CompareTo(default(T)) > 0) { if (newvalue.CompareTo(Max) > 0) { return(false); } } return(true); }
public void Summarize(object value) { string myvalue = value.ToString(); Count++; if (Count > 1) { if (Function == SummaryFunctionsText.Max) { Max = (Max.CompareTo(myvalue) > 0) ? Max : myvalue; } else if (Function == SummaryFunctionsText.Min) { Min = (Min.CompareTo(myvalue) > 0) ? myvalue : Min; } } else { if (Function == SummaryFunctionsText.Max) { Max = myvalue; } else if (Function == SummaryFunctionsText.Min) { Min = myvalue; } } }
internal bool FitsValue(ulong value) // TODO: doc and make public { if (!IsNumeric) { throw new InvalidOperationException(Numeric.ERR_NOT_ISNUMERIC); } return(Max.CompareTo(value) >= 0 && Min.CompareTo(value) <= 0); }
public NumericValue(T value, T min, T max) { _value = value.CompareTo(max) > 0 ? max : value.CompareTo(min) < 0 ? min : value; Max = max; Min = min; if (Max.CompareTo(Min) < 0) { throw new ArgumentException(); } }
/// <summary> Returns the range that represents the intersection of this range and <code>value</code>. </summary> /// <param name="value">The range to intersect with.</param> /// <returns> /// A range that contains the values that are common in both ranges, /// or null if there is no intersection. /// </returns> public Range <T> Intersect([NotNull] Range <T> value) { if (!Overlaps(value)) { return(null); } var start = Min.CompareTo(value.Min) > 0 ? Min : value.Min; return(Max.CompareTo(value.Max) < 0 ? new Range <T>(start, Max) : new Range <T>(start, value.Max)); }
/// <inheritdoc /> public override string ToString() { var result = new StringBuilder(); result.Append(Min.CompareTo(IncludedMin) == 0 ? '[' : ')'); result.Append(Min); result.Append(".."); result.Append(Max); result.Append(Max.CompareTo(IncludedMax) == 0 ? ']' : '('); return(result.ToString()); }
public bool Includes(T value) { if (Min.CompareTo(value) > 0) { return(false); } if (Max.CompareTo(value) < 0) { return(false); } return(true); }
public NumericValue(T value, T min, T max) { //This is made to prevent editor overriding values changed using text editors. StructDataEditor still cant go beyond bounds, but external text editors can. _value = value; //_value = value.CompareTo(max) > 0 ? max : value.CompareTo(min) < 0 ? min : value; Max = max; Min = min; if (Max.CompareTo(Min) < 0) { throw new ArgumentException(); } }
internal Range <T> Intersect(Range <T> other) { if (IsOverlapped(other)) { var newMin = Min.CompareTo(other.Min) > 0 ? Min : other.Min; var newMax = Max.CompareTo(other.Max) < 0 ? Max : other.Max; return(new Range <T>(newMin, newMax)); } else { return(null); } }
public IEnumerable <T> Iterate([NotNull] Func <T, T> incrementor) { yield return(Min); var item = incrementor(Min); while (Max.CompareTo(item) >= 0) { yield return(item); item = incrementor(item); } }
protected Pv2DigitParamType(string paramName, string description, string groupName, string formatString, string units, TValue min, TValue max, TValue defaultValue, Pv2ParamFlags flags) : base(paramName, description, groupName, defaultValue, flags) { FormatString = formatString; Units = units; Min = min; Max = max; if (Max.CompareTo(Min) < 0) { throw new ArgumentException($"Max < Min {Max} <= {Min}"); } Validate(DefaultValue); }
public bool GetIntersection(Interval other, out Interval result) { int a = Min.CompareTo(other.Min); int b = Max.CompareTo(other.Max); int c = Min.CompareTo(other.Max); int d = Max.CompareTo(other.Min); result = new Interval( (a >= 0) ? Min : other.Min, (b <= 0) ? Max : other.Max ); return(Math.Sign(c) != Math.Sign(d)); }
/// <summary> /// Sets Min and Max properties according to given range type and current value /// </summary> /// <param name="rangeKind">The type of range</param> public void SetRange(RangeKind rangeKind) { var rangeValue = _ranges[rangeKind]; Min = Minus(Value, rangeValue); Max = Plus(Value, rangeValue); // check if we are outside the (DefaultMin, DefaultMax) if (Min.CompareTo(DefaultMin) < 0) { Min = DefaultMin; } if (Max.CompareTo(DefaultMax) > 0) { Max = DefaultMax; } }
/// <summary> Returns the range that represents the union of this range and <code>value</code>. </summary> /// <param name="value">The range to union with.</param> /// <returns>A range that contains both ranges.</returns> public Range <T> Union([NotNull] Range <T> value) { // If either one is a subset of the other, then it is the union if (Contains(value)) { return(this); } if (value.Contains(this)) { return(value); } var start = Min.CompareTo(value.Min) < 0 ? Min : value.Min; return(Max.CompareTo(value.Max) > 0 ? new Range <T>(start, Max) : new Range <T>(start, value.Max)); }
public IEnumerable <Range <T> > Split([NotNull] T position) { if (!Contains(position)) { yield break; } if ((Min.CompareTo(position) == 0) || (Max.CompareTo(position) == 0)) { // The position is at a boundary, so a split does not happen yield return(this); } else { yield return(new Range <T>(Min, position)); yield return(new Range <T>(position, Max)); } }
public Range <T> Complement([NotNull] Range <T> value) { if (Contains(value)) { return(null); } if (Overlaps(value)) { // If value's start and end straddle our start, move our start up to be values end. var start = (Min.CompareTo(value.Min) > 0) && (Min.CompareTo(value.Max) < 0) ? value.Max : Min; // If value's start and end straddle our end, move our end back down to be values start. return((Max.CompareTo(value.Min) > 0) && (Max.CompareTo(value.Max) < 0) ? new Range <T>(start, value.Min) : new Range <T>(start, Max)); } return(this); }
/// <summary> /// checks if the given value is in range of this entry /// </summary> /// <param name="value"></param> /// <returns></returns> public virtual bool InRange(TDimension value) { if (hasValue) { if (Value == null && value == null) { return(true); } else if (Value == null) { return(false); } else { return(Value.CompareTo(value) == 0); } } else { return(Min.CompareTo(value) <= 0 && Max.CompareTo(value) > 0); } }
internal bool FitsIntValue <TIntegral>(TIntegral value) // TODO: doc and make public? { if (!IsNumeric) { throw new InvalidOperationException(Numeric.ERR_NOT_ISNUMERIC); } var conv = value as IConvertible; if (conv == null) { return(false); } var tcVal = conv.GetTypeCode(); if (!Numeric.IsInteger(tcVal)) { return(false); } // (check if TypeCodes are identical first before proceeding to more expensive operations) if ((int)tcVal == tc) { return(true); } if (Numeric.IsUnsigned(tcVal)) { ulong v64 = conv.ToUInt64(null); return(Max.CompareTo(v64) >= 0 && Min.CompareTo(v64) <= 0); } else { long v64 = conv.ToInt64(null); return(Max.CompareTo(v64) >= 0 && Min.CompareTo(v64) <= 0); } }
public List <T> CheckOverlapping(Range <T> other) { if (Min.CompareTo(other.Max) <= 0 && other.Min.CompareTo(Max) <= 0) { T begin = Min; T end = Max; if (Max.CompareTo(other.Max) >= 0) { begin = other.Max; } if (Min.CompareTo(other.Min) <= 0) { end = other.Min; } List <T> res = new List <T>(); res.Add(begin); res.Add(end); return(res); } return(null); }
/// <summary> /// Compares <b><i>this</i></b> to <paramref name="other"/> using <see cref="CompareTo"/> calls against multiple properties: /// <li><see cref="Min"/></li> /// <li><see cref="Max"/></li> /// <li><see cref="Average"/></li> /// Returns -1 or 1 if <b>any</b> properties return that value and <b>none</b> return the other; /// otherwise, returns 0. /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo([NotNull] AggregateExecutionTime other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } return(Average.CompareTo(other.Average)); var minCompare = Min.CompareTo(other.Min); var maxCompare = Max.CompareTo(other.Max); var avgCompare = Average.CompareTo(other.Average); var compares = new int[] { minCompare, maxCompare, avgCompare }; Console.WriteLine( new Dictionary <object, object>() { [$"Min: {Min}, {other.Min}"] = minCompare, [$"Max: {Max}, {other.Max}"] = maxCompare, [$"Avg: {Average}, {other.Average}"] = avgCompare }.Prettify() ); if (compares.Any(it => it > 0) && compares.All(it => it >= 0)) { return(1); } else if (compares.Any(it => it < 0) && compares.All(it => it <= 0)) { return(-1); } else { return(0); } }
/// <summary> Indicates if the range contains <code>value</code>. </summary> /// <param name="value">A range to test.</param> /// <returns>true if the entire range in <code>value</code> is within this range.</returns> public bool Contains([NotNull] Range <T> value) { return((Min.CompareTo(value.Min) <= 0) && (Max.CompareTo(value.Max) >= 0)); }
public bool Includes(T item) { return(Min.CompareTo(item) <= 0 && Max.CompareTo(item) >= 0); }
/// <summary> Indicates if the range contains <code>value</code>. </summary> /// <param name="value">The value to look for.</param> /// <returns>true if the range contains <code>value</code>, false otherwise.</returns> public bool Contains([NotNull] T value) { return((Min.CompareTo(value) <= 0) && (Max.CompareTo(value) >= 0)); }