Struct NumericRange
Represents a double range with minimum and maximum values, where values are single-precision double numbers.
Namespace: ISynergy.Framework.Core.Ranges
Assembly: ISynergy.Framework.Core.dll
Syntax
public struct NumericRange
Remarks
This class represents a double range with inclusive limits, where both minimum and maximum values of the range are included into it. Mathematical notation of such range is [min, max].
Examples
// create [0.25, 1.5] range
var range1 = new SingleRange(0.25f, 1.5f);
// create [1.00, 2.25] range
var range2 = new SingleRange(1.00f, 2.25f);
// check if values is inside of the first range
if (range1.IsInside(0.75f))
{
// ...
}
// check if the second range is inside of the first range
if (range1.IsInside(range2))
{
// ...
}
// check if two ranges overlap
if (range1.IsOverlapping(range2))
{
// ...
}
Constructors
View SourceNumericRange(Byte, Byte, Boolean, Int32)
Initializes a new instance of the NumericRange class.
Declaration
public NumericRange(byte min, byte max, bool round = false, int decimals = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte | min | Minimum value of the range. |
| System.Byte | max | Maximum value of the range. |
| System.Boolean | round | |
| System.Int32 | decimals |
NumericRange(Decimal, Decimal, Boolean, Int32)
Initializes a new instance of the NumericRange class.
Declaration
public NumericRange(decimal min, decimal max, bool round = false, int decimals = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | min | Minimum value of the range. |
| System.Decimal | max | Maximum value of the range. |
| System.Boolean | round | |
| System.Int32 | decimals |
NumericRange(Double, Double, Boolean, Int32)
Initializes a new instance of the NumericRange class.
Declaration
public NumericRange(double min, double max, bool round = false, int decimals = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | min | Minimum value of the range. |
| System.Double | max | Maximum value of the range. |
| System.Boolean | round | |
| System.Int32 | decimals |
NumericRange(Int32, Int32, Boolean, Int32)
Initializes a new instance of the NumericRange class.
Declaration
public NumericRange(int min, int max, bool round = false, int decimals = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | min | Minimum value of the range. |
| System.Int32 | max | Maximum value of the range. |
| System.Boolean | round | |
| System.Int32 | decimals |
NumericRange(Int64, Int64, Boolean, Int32)
Initializes a new instance of the NumericRange class.
Declaration
public NumericRange(long min, long max, bool round = false, int decimals = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | min | Minimum value of the range. |
| System.Int64 | max | Maximum value of the range. |
| System.Boolean | round | |
| System.Int32 | decimals |
NumericRange(Single, Single, Boolean, Int32)
Initializes a new instance of the NumericRange class.
Declaration
public NumericRange(float min, float max, bool round = false, int decimals = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | min | Minimum value of the range. |
| System.Single | max | Maximum value of the range. |
| System.Boolean | round | |
| System.Int32 | decimals |
Properties
View SourceLength
Gets the length of the range, defined as (max - min).
Declaration
public readonly double Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Max
Maximum value of the range.
Declaration
public double Max { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Remarks
Represents maximum value (right side limit) of the range [min, max].
Min
Minimum value of the range.
Declaration
public double Min { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Remarks
Represents minimum value (left side limit) of the range [min, max].
Methods
View SourceEquals(NumericRange)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(NumericRange other)
Parameters
| Type | Name | Description |
|---|---|---|
| NumericRange | other | An object to compare with this object. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if the current object is equal to the |
Equals(Object)
Determines whether the specified
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
GetEnumerator()
Returns an enumerator that iterates through a collection.
Declaration
public IEnumerator<double> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<System.Double> | An System.Collections.IEnumerator object that can be used to iterate through the collection. |
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Intersection(NumericRange)
Computes the intersection between two ranges.
Declaration
public NumericRange Intersection(NumericRange range)
Parameters
| Type | Name | Description |
|---|---|---|
| NumericRange | range | The second range for which the intersection should be calculated. |
Returns
| Type | Description |
|---|---|
| NumericRange | An new NumericRange structure containing the intersection
between this range and the |
IsInside(NumericRange)
Check if the specified range is inside of the range.
Declaration
public bool IsInside(NumericRange range)
Parameters
| Type | Name | Description |
|---|---|---|
| NumericRange | range | Range to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the specified range is inside of the range or false otherwise. |
IsInside(Double)
Check if the specified value is inside of the range.
Declaration
public bool IsInside(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | x | Value to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the specified value is inside of the range or false otherwise. |
IsOverlapping(NumericRange)
Check if the specified range overlaps with the range.
Declaration
public bool IsOverlapping(NumericRange range)
Parameters
| Type | Name | Description |
|---|---|---|
| NumericRange | range | Range to check for overlapping. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the specified range overlaps with the range or false otherwise. |
ToRange(Boolean)
Converts this single-precision range into an NumericRange.
Declaration
public NumericRange ToRange(bool provideInnerRange)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | provideInnerRange | Specifies if inner integer range must be returned or outer range. |
Returns
| Type | Description |
|---|---|
| NumericRange | Returns integer version of the range. |
Remarks
If provideInnerRange is set to true, then the
returned integer range will always fit inside of the current single precision range.
If it is set to false, then current single precision range will always
fit into the returned integer range.
ToString()
Returns a
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A |
ToString(String, IFormatProvider)
Returns a
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | format | The format. |
| IFormatProvider | formatProvider | The format provider. |
Returns
| Type | Description |
|---|---|
| System.String | A |
Operators
View SourceEquality(NumericRange, NumericRange)
Determines whether two instances are equal.
Declaration
public static bool operator ==(NumericRange range1, NumericRange range2)
Parameters
| Type | Name | Description |
|---|---|---|
| NumericRange | range1 | |
| NumericRange | range2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Inequality(NumericRange, NumericRange)
Determines whether two instances are not equal.
Declaration
public static bool operator !=(NumericRange range1, NumericRange range2)
Parameters
| Type | Name | Description |
|---|---|---|
| NumericRange | range1 | |
| NumericRange | range2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |