namespace Hawkeye.VisionBuilder.Workflow.ColorStudioClasses
{
/// The Range class.
/// Generic parameter.
public class Range where T : IComparable
{
public Range()
{
}
public Range(T min,T max)
{
this.Maximum = max;
this.Minimum = min;
}
/// Minimum value of the range.
public T Minimum { get; set; }
/// Maximum value of the range.
public T Maximum { get; set; }
/// Presents the Range in readable format.
/// String representation of the Range
public override string ToString()
{
return string.Format("[{0} - {1}]", this.Minimum, this.Maximum);
}
/// Determines if the range is valid.
/// True if range is valid, else false
public bool IsValid()
{
return this.Minimum.CompareTo(this.Maximum) <= 0;
}
/// Determines if the provided value is inside the range.
/// The value to test
/// True if the value is inside Range, else false
public bool ContainsValue(T value)
{
return (this.Minimum.CompareTo(value) <= 0) && (value.CompareTo(this.Maximum) <= 0);
}
/// Determines if this Range is inside the bounds of another range.
/// The parent range to test on
/// True if range is inclusive, else false
public bool IsInsideRange(Range range)
{
return this.IsValid() && range.IsValid() && range.ContainsValue(this.Minimum) && range.ContainsValue(this.Maximum);
}
/// Determines if another range is inside the bounds of this range.
/// The child range to test
/// True if range is inside, else false
public bool ContainsRange(Range range)
{
return this.IsValid() && range.IsValid() && this.ContainsValue(range.Minimum) && this.ContainsValue(range.Maximum);
}
}
}