1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:03:22 +08:00

Fix div-by-zero errors with autoplay

This commit is contained in:
smoogipoo 2020-06-22 20:32:04 +09:00
parent 5c4df2e32c
commit ff2f3a8484
2 changed files with 28 additions and 4 deletions

View File

@ -3,6 +3,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
@ -15,7 +17,25 @@ namespace osu.Game.Tests.Visual.Ranking
{
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
{
public TestSceneHitEventTimingDistributionGraph()
[Test]
public void TestManyDistributedEvents()
{
createTest(CreateDistributedHitEvents());
}
[Test]
public void TestZeroTimeOffset()
{
createTest(Enumerable.Range(0, 100).Select(_ => new HitEvent(0, HitResult.Perfect, new HitCircle(), new HitCircle(), null)).ToList());
}
[Test]
public void TestNoEvents()
{
createTest(new List<HitEvent>());
}
private void createTest(List<HitEvent> events) => AddStep("create test", () =>
{
Children = new Drawable[]
{
@ -24,14 +44,14 @@ namespace osu.Game.Tests.Visual.Ranking
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
new HitEventTimingDistributionGraph(CreateDistributedHitEvents())
new HitEventTimingDistributionGraph(events)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(400, 130)
Size = new Vector2(600, 130)
}
};
}
});
public static List<HitEvent> CreateDistributedHitEvents()
{

View File

@ -58,8 +58,12 @@ namespace osu.Game.Screens.Ranking.Statistics
return;
int[] bins = new int[total_timing_distribution_bins];
double binSize = Math.Ceiling(hitEvents.Max(e => Math.Abs(e.TimeOffset)) / timing_distribution_bins);
// Prevent div-by-0 by enforcing a minimum bin size
binSize = Math.Max(1, binSize);
foreach (var e in hitEvents)
{
int binOffset = (int)(e.TimeOffset / binSize);