// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using System.Linq; using osu.Framework.Utils; using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Edit.Checks.Components { public static class TimingCheckUtils { // Tolerance for exact time offset matching (in milliseconds) public const double TIME_OFFSET_TOLERANCE_MS = 0.01; /// /// Finds a timing control point that starts at approximately the same time (within 1ms after rounding). /// /// The collection of timing points to search. /// The time to match against. /// The matching timing control point, or null if none found. public static TimingControlPoint? FindMatchingTimingPoint(IEnumerable timingPoints, double time) { return timingPoints.FirstOrDefault(tp => (int)tp.Time == (int)time); } /// /// Finds a timing control point that starts at precisely the same time (within timing tolerance). /// /// The collection of timing points to search. /// The time to match against. /// The exact matching timing control point, or null if none found. public static TimingControlPoint? FindExactMatchingTimingPoint(IEnumerable timingPoints, double time) { return timingPoints.FirstOrDefault(tp => Precision.AlmostEquals(tp.Time, time, TIME_OFFSET_TOLERANCE_MS)); } } }