mirror of
https://github.com/ppy/osu.git
synced 2025-02-06 02:46:08 +08:00
Fix div-by-zero errors with autoplay
This commit is contained in:
parent
5c4df2e32c
commit
ff2f3a8484
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
@ -15,7 +17,25 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
{
|
{
|
||||||
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
|
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[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -24,14 +44,14 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = Color4Extensions.FromHex("#333")
|
Colour = Color4Extensions.FromHex("#333")
|
||||||
},
|
},
|
||||||
new HitEventTimingDistributionGraph(CreateDistributedHitEvents())
|
new HitEventTimingDistributionGraph(events)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(400, 130)
|
Size = new Vector2(600, 130)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
|
|
||||||
public static List<HitEvent> CreateDistributedHitEvents()
|
public static List<HitEvent> CreateDistributedHitEvents()
|
||||||
{
|
{
|
||||||
|
@ -58,8 +58,12 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
int[] bins = new int[total_timing_distribution_bins];
|
int[] bins = new int[total_timing_distribution_bins];
|
||||||
|
|
||||||
double binSize = Math.Ceiling(hitEvents.Max(e => Math.Abs(e.TimeOffset)) / 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)
|
foreach (var e in hitEvents)
|
||||||
{
|
{
|
||||||
int binOffset = (int)(e.TimeOffset / binSize);
|
int binOffset = (int)(e.TimeOffset / binSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user