2022-05-01 00:33:22 -05:00
|
|
|
using System;
|
|
|
|
|
2024-08-31 18:56:48 +02:00
|
|
|
namespace ConfusedPolarBear.Plugin.IntroSkipper.Data;
|
2022-05-01 00:33:22 -05:00
|
|
|
|
2022-07-05 16:21:13 -05:00
|
|
|
#pragma warning disable CA1036 // Override methods on comparable types
|
2022-05-31 16:12:11 -05:00
|
|
|
|
2022-05-01 00:33:22 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Range of contiguous time.
|
|
|
|
/// </summary>
|
|
|
|
public class TimeRange : IComparable
|
|
|
|
{
|
2022-05-03 01:09:50 -05:00
|
|
|
/// <summary>
|
2022-05-09 22:50:41 -05:00
|
|
|
/// Initializes a new instance of the <see cref="TimeRange"/> class.
|
2022-05-03 01:09:50 -05:00
|
|
|
/// </summary>
|
|
|
|
public TimeRange()
|
|
|
|
{
|
|
|
|
Start = 0;
|
|
|
|
End = 0;
|
|
|
|
}
|
|
|
|
|
2022-05-01 00:33:22 -05:00
|
|
|
/// <summary>
|
2022-05-09 22:50:41 -05:00
|
|
|
/// Initializes a new instance of the <see cref="TimeRange"/> class.
|
2022-05-01 00:33:22 -05:00
|
|
|
/// </summary>
|
2022-05-09 22:50:41 -05:00
|
|
|
/// <param name="start">Time range start.</param>
|
|
|
|
/// <param name="end">Time range end.</param>
|
2022-05-01 00:33:22 -05:00
|
|
|
public TimeRange(double start, double end)
|
|
|
|
{
|
|
|
|
Start = start;
|
|
|
|
End = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-09 22:50:41 -05:00
|
|
|
/// Initializes a new instance of the <see cref="TimeRange"/> class.
|
2022-05-01 00:33:22 -05:00
|
|
|
/// </summary>
|
2022-05-09 22:50:41 -05:00
|
|
|
/// <param name="original">Original TimeRange.</param>
|
2022-05-01 00:33:22 -05:00
|
|
|
public TimeRange(TimeRange original)
|
|
|
|
{
|
|
|
|
Start = original.Start;
|
|
|
|
End = original.End;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2022-05-09 22:56:03 -05:00
|
|
|
/// Gets or sets the time range start (in seconds).
|
2022-05-01 00:33:22 -05:00
|
|
|
/// </summary>
|
2022-05-09 22:56:03 -05:00
|
|
|
public double Start { get; set; }
|
2022-05-01 00:33:22 -05:00
|
|
|
|
2022-05-09 22:56:03 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the time range end (in seconds).
|
|
|
|
/// </summary>
|
|
|
|
public double End { get; set; }
|
2022-05-01 00:33:22 -05:00
|
|
|
|
2022-05-09 22:56:03 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the duration of this time range (in seconds).
|
|
|
|
/// </summary>
|
|
|
|
public double Duration => End - Start;
|
2022-05-01 00:33:22 -05:00
|
|
|
|
2022-05-09 22:56:03 -05:00
|
|
|
/// <summary>
|
2022-05-31 16:12:11 -05:00
|
|
|
/// Compare TimeRange durations.
|
2022-05-09 22:56:03 -05:00
|
|
|
/// </summary>
|
2022-05-31 16:12:11 -05:00
|
|
|
/// <param name="obj">Object to compare with.</param>
|
|
|
|
/// <returns>int.</returns>
|
2022-05-09 22:56:03 -05:00
|
|
|
public int CompareTo(object? obj)
|
|
|
|
{
|
2022-05-31 16:12:11 -05:00
|
|
|
if (!(obj is TimeRange tr))
|
2022-05-09 22:56:03 -05:00
|
|
|
{
|
2022-05-31 16:12:11 -05:00
|
|
|
throw new ArgumentException("obj must be a TimeRange");
|
2022-05-09 22:56:03 -05:00
|
|
|
}
|
|
|
|
|
2022-05-31 16:12:11 -05:00
|
|
|
return tr.Duration.CompareTo(Duration);
|
2022-05-09 22:56:03 -05:00
|
|
|
}
|
2022-08-29 23:56:13 -05:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests if this TimeRange object intersects the provided TimeRange.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tr">Second TimeRange object to test.</param>
|
|
|
|
/// <returns>true if tr intersects the current TimeRange, false otherwise.</returns>
|
|
|
|
public bool Intersects(TimeRange tr)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
(Start < tr.Start && tr.Start < End) ||
|
|
|
|
(Start < tr.End && tr.End < End);
|
|
|
|
}
|
2022-05-01 00:33:22 -05:00
|
|
|
}
|