diff --git a/osu.Game/Rulesets/Edit/Checks/CheckInconsistentTimingControlPoints.cs b/osu.Game/Rulesets/Edit/Checks/CheckInconsistentTimingControlPoints.cs index b8694c52cc..bbed49d7ee 100644 --- a/osu.Game/Rulesets/Edit/Checks/CheckInconsistentTimingControlPoints.cs +++ b/osu.Game/Rulesets/Edit/Checks/CheckInconsistentTimingControlPoints.cs @@ -3,18 +3,12 @@ using System; using System.Collections.Generic; -using System.Linq; -using osu.Framework.Utils; -using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets.Edit.Checks.Components; namespace osu.Game.Rulesets.Edit.Checks { public class CheckInconsistentTimingControlPoints : ICheck { - // Small tolerance for floating point comparison - private const double timing_tolerance = 0.01; - public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Timing, "Inconsistent timing control points"); public IEnumerable PossibleTemplates => new IssueTemplate[] @@ -47,8 +41,8 @@ namespace osu.Game.Rulesets.Edit.Checks // Check each timing point in the reference against this difficulty foreach (var referencePoint in referenceTimingPoints) { - var matchingPoint = findMatchingTimingPoint(timingPoints, referencePoint.Time); - var exactMatchingPoint = findExactMatchingTimingPoint(timingPoints, referencePoint.Time); + var matchingPoint = TimingCheckUtils.FindMatchingTimingPoint(timingPoints, referencePoint.Time); + var exactMatchingPoint = TimingCheckUtils.FindExactMatchingTimingPoint(timingPoints, referencePoint.Time); if (matchingPoint == null) { @@ -63,7 +57,7 @@ namespace osu.Game.Rulesets.Edit.Checks } // Check for BPM inconsistency - if (Math.Abs(referencePoint.BeatLength - matchingPoint.BeatLength) > timing_tolerance) + if (Math.Abs(referencePoint.BeatLength - matchingPoint.BeatLength) > TimingCheckUtils.TIMING_TOLERANCE) { yield return new IssueTemplateInconsistentBPM(this).Create(referencePoint.Time, beatmap.BeatmapInfo.DifficultyName); } @@ -79,8 +73,8 @@ namespace osu.Game.Rulesets.Edit.Checks // Check timing points in this difficulty that aren't in the reference foreach (var timingPoint in timingPoints) { - var matchingReferencePoint = findMatchingTimingPoint(referenceTimingPoints, timingPoint.Time); - var exactMatchingReferencePoint = findExactMatchingTimingPoint(referenceTimingPoints, timingPoint.Time); + var matchingReferencePoint = TimingCheckUtils.FindMatchingTimingPoint(referenceTimingPoints, timingPoint.Time); + var exactMatchingReferencePoint = TimingCheckUtils.FindExactMatchingTimingPoint(referenceTimingPoints, timingPoint.Time); if (matchingReferencePoint == null) { @@ -94,16 +88,6 @@ namespace osu.Game.Rulesets.Edit.Checks } } - private static TimingControlPoint? findMatchingTimingPoint(IEnumerable timingPoints, double time) - { - return timingPoints.FirstOrDefault(tp => Precision.AlmostEquals(tp.Time, Math.Round(time), 1.0)); - } - - private static TimingControlPoint? findExactMatchingTimingPoint(IEnumerable timingPoints, double time) - { - return timingPoints.FirstOrDefault(tp => Precision.AlmostEquals(tp.Time, time, timing_tolerance)); - } - public class IssueTemplateMissingTimingPoint : IssueTemplate { public IssueTemplateMissingTimingPoint(ICheck check) diff --git a/osu.Game/Rulesets/Edit/Checks/Components/TimingCheckUtils.cs b/osu.Game/Rulesets/Edit/Checks/Components/TimingCheckUtils.cs new file mode 100644 index 0000000000..1ddbeb31d6 --- /dev/null +++ b/osu.Game/Rulesets/Edit/Checks/Components/TimingCheckUtils.cs @@ -0,0 +1,39 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +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 + { + // Small tolerance for floating point comparison + public const double TIMING_TOLERANCE = 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 => Precision.AlmostEquals(tp.Time, Math.Round(time), 1.0)); + } + + /// + /// 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, TIMING_TOLERANCE)); + } + } +}