mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:23:22 +08:00
Replace iterated addition with rounding
This commit is contained in:
parent
1551c42c12
commit
39cfbb67ad
@ -483,12 +483,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
|
|||||||
if (!(HitObject is IHasPathWithRepeats curveData))
|
if (!(HitObject is IHasPathWithRepeats curveData))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// mathematically speaking this could be done by calculating (time - HitObject.StartTime) / SegmentDuration
|
// mathematically speaking this should be a whole number always, but floating-point arithmetic is not so kind
|
||||||
// however, floating-point operations can introduce inaccuracies - therefore resort to iterated addition
|
var index = (int)Math.Round(SegmentDuration == 0 ? 0 : (time - HitObject.StartTime) / SegmentDuration, MidpointRounding.AwayFromZero);
|
||||||
// (all callers use this method to calculate repeat point times, so this way is consistent and deterministic)
|
|
||||||
int index = 0;
|
|
||||||
for (double nodeTime = HitObject.StartTime; nodeTime < time; nodeTime += SegmentDuration)
|
|
||||||
index += 1;
|
|
||||||
|
|
||||||
// avoid slicing the list & creating copies, if at all possible.
|
// avoid slicing the list & creating copies, if at all possible.
|
||||||
return index == 0 ? curveData.NodeSamples : curveData.NodeSamples.Skip(index).ToList();
|
return index == 0 ? curveData.NodeSamples : curveData.NodeSamples.Skip(index).ToList();
|
||||||
|
Loading…
Reference in New Issue
Block a user