示例#1
0
 /// <summary>
 /// Sets a greater value if the it is not in the interval.
 /// If the parameter is greater than MaxValue, this value will instead MaxValue; otherwise, nothing will be changed.
 /// </summary>
 /// <param name="interval">The interval to be filled.</param>
 /// <param name="value">A greater value to make sure the interval can include.</param>
 public static void SetGreaterValue <T>(this ISimpleInterval <T> interval, T value)
 {
     if (interval.IsGreaterThanOrEqualMaxValue(value))
     {
         interval.MaxValue = value;
     }
 }
示例#2
0
 /// <summary>
 /// Sets a less value if the it is not in the interval.
 /// If the parameter is less than MinValue, this value will instead MinValue; otherwise, nothing will be changed.
 /// </summary>
 /// <param name="interval">The interval to be filled.</param>
 /// <param name="value">A less value to make sure the interval can include.</param>
 public static void SetLessValue <T>(this ISimpleInterval <T> interval, T value)
 {
     if (interval.IsLessThanOrEqualMinValue(value))
     {
         interval.MinValue = value;
     }
 }
示例#3
0
 /// <summary>
 /// Sets a less value if the it is not in the interval.
 /// If the parameter is less than MinValue, this value will instead MinValue; otherwise, nothing will be changed.
 /// </summary>
 /// <param name="interval">The interval to be filled.</param>
 /// <param name="value">A less value to make sure the interval can include.</param>
 /// <param name="leftOpen">true if it is left open; otherwise, left closed.</param>
 public static void SetLessValue <T>(this ISimpleInterval <T> interval, T value, bool leftOpen)
 {
     interval.LeftOpen = leftOpen;
     if (interval.IsLessThanOrEqualMinValue(value))
     {
         interval.MinValue = value;
     }
 }
示例#4
0
 /// <summary>
 /// Sets a greater value if the it is not in the interval.
 /// If the parameter is greater than MaxValue, this value will instead MaxValue; otherwise, nothing will be changed.
 /// </summary>
 /// <param name="interval">The interval to be filled.</param>
 /// <param name="value">A greater value to make sure the interval can include.</param>
 /// <param name="rightOpen">true if it is right open; otherwise, right closed.</param>
 public static void SetGreaterValue <T>(this ISimpleInterval <T> interval, T value, bool rightOpen)
 {
     interval.RightOpen = rightOpen;
     if (interval.IsGreaterThanOrEqualMaxValue(value))
     {
         interval.MaxValue = value;
     }
 }
示例#5
0
    /// <summary>
    /// Checks if a value is in the interval.
    /// </summary>
    /// <param name="interval">The interval to compare.</param>
    /// <param name="value">A value to check.</param>
    /// <returns>true if the value is in the interval; otherwise, false.</returns>
    public static bool IsInInterval <T>(this ISimpleInterval <T> interval, T value)
    {
        var compareLeft = interval.LeftOpen ? interval.IsGreaterThanMinValue(value) : interval.IsGreaterThanOrEqualMinValue(value);

        if (!compareLeft)
        {
            return(false);
        }
        return(interval.RightOpen ? interval.IsLessThanMaxValue(value) : interval.IsLessThanOrEqualMaxValue(value));
    }
示例#6
0
 /// <summary>
 /// Loads a copier into current instance.
 /// </summary>
 /// <param name="interval">The interval to be filled.</param>
 /// <param name="value">The instance to copy.</param>
 public static void Load <T>(this ISimpleInterval <T> interval, ISimpleInterval <T> value)
 {
     if (value == null)
     {
         return;
     }
     interval.MinValue  = value.MinValue;
     interval.MaxValue  = value.MaxValue;
     interval.LeftOpen  = value.LeftOpen;
     interval.RightOpen = value.RightOpen;
 }
示例#7
0
    /// <summary>
    /// Sets the values for the simple closed interval.
    /// The greater one will be set as MaxValue, the less one will be set as MinValue.
    /// </summary>
    /// <param name="interval">The interval to be filled.</param>
    /// <param name="valueA">The first value.</param>
    /// <param name="valueB">The seconde value.</param>
    public static void SetValues <T>(this ISimpleInterval <T> interval, T valueA, T valueB)
    {
        if (interval.IsGreaterThanOrEqualMinValue(valueA))
        {
            interval.MaxValue = valueA;
        }
        interval.MinValue = valueA;
        interval.MaxValue = valueA;
        if (interval.IsGreaterThanOrEqualMinValue(valueB) || interval.IsGreaterThanOrEqualMaxValue(valueB))
        {
            interval.MaxValue = valueB;
            return;
        }

        interval.MinValue = valueB;
        interval.MaxValue = valueA;
    }
示例#8
0
 /// <summary>
 /// Sets the values for the simple closed interval.
 /// The greater one will be set as MaxValue, the less one will be set as MinValue.
 /// </summary>
 /// <param name="interval">The interval to be filled.</param>
 /// <param name="valueA">The first value.</param>
 /// <param name="valueB">The seconde value.</param>
 /// <param name="leftOpen">true if it is left open; otherwise, left closed.</param>
 /// <param name="rightOpen">true if it is right open; otherwise, right closed.</param>
 public static void SetValues <T>(this ISimpleInterval <T> interval, T valueA, T valueB, bool leftOpen, bool rightOpen)
 {
     interval.LeftOpen  = leftOpen;
     interval.RightOpen = rightOpen;
     interval.SetValues(valueA, valueB);
 }
示例#9
0
 /// <summary>
 /// Checks if the value is greater than or equal MaxValue.
 /// </summary>
 /// <param name="interval">The interval to compare.</param>
 /// <param name="value">A value to compare with MaxValue.</param>
 /// <returns>true if the specific value is greater than or equal MaxValue; otherwise, false.</returns>
 public static bool IsGreaterThanOrEqualMaxValue <T>(this ISimpleInterval <T> interval, T value)
 {
     return(interval.IsGreaterThanMaxValue(value) || interval.EqualsMaxValue(value));
 }
示例#10
0
 /// <summary>
 /// Checks if the value is less than or equal MinValue.
 /// </summary>
 /// <param name="interval">The interval to compare.</param>
 /// <param name="value">A value to compare with MinValue.</param>
 /// <returns>true if the specific value is less than or equal MinValue; otherwise, false.</returns>
 public static bool IsLessThanOrEqualMinValue <T>(this ISimpleInterval <T> interval, T value)
 {
     return(interval.IsLessThanMinValue(value) || interval.EqualsMinValue(value));
 }