namespace VideoBrowser.Common
{
using System;
using VideoBrowser.Extensions;
using VideoBrowser.If;
///
/// Defines the
///
public struct RangeDouble : IRange
{
private const double PRECISION = 1E-6;
///
/// Initializes a new instance of the class.
///
/// The start
/// The end
/// The allowInvert
public RangeDouble(double start, double end, bool allowInvert = false)
{
if (!allowInvert && start >= end)
{
throw new ArgumentException($"{nameof(start)} is equal or greater than {nameof(end)}");
}
this.Start = start;
this.End = end;
}
///
/// Gets the Empty
///
public static RangeDouble Empty { get; } = new RangeDouble();
///
/// Gets the End
///
public double End { get; }
///
/// Gets the Start
///
public double Start { get; }
///
/// The Equals
///
/// The other
/// The
public bool Equals(IRange other)
{
return Equals(this.Start, other.Start) && Equals(this.End, other.End);
}
///
/// The Equals
///
/// The
/// The
public override bool Equals(object obj)
{
if (!(obj is RangeDouble))
{
return false;
}
return this == (RangeDouble)obj;
}
/// Equalses the specified other.
/// The other.
public bool Equals(RangeDouble other)
{
return this.Start.IsEqualTo(other.Start, PRECISION) && this.End.IsEqualTo(other.End, PRECISION);
}
///
/// The GetHashCode
///
/// The
public override int GetHashCode()
{
var startHash = this.Start.GetHashCode();
var endHash = this.End.GetHashCode();
return startHash ^ (startHash << 8) ^ endHash ^ (endHash << 4);
}
///
/// The ToString
///
/// The
public override string ToString()
{
return $"Start:{this.Start.Format()};End:{this.End.Format()};Length:{this.Length().Format()}";
}
///
/// Implements the operator ==.
///
/// The left.
/// The right.
/// The result of the operator.
public static bool operator ==(RangeDouble left, RangeDouble right)
{
return left.Start.IsEqualTo(right.Start, PRECISION) && left.End.IsEqualTo(right.End, PRECISION);
}
///
/// Implements the operator !=.
///
/// The left.
/// The right.
/// The result of the operator.
public static bool operator !=(RangeDouble left, RangeDouble right)
{
return !(left == right);
}
}
}