mirror of
https://github.com/ppy/osu
synced 2025-03-22 02:47:04 +00:00
Merge pull request #17068 from peppy/fix-hit-distribution-rounding
Fix hit distribution graph midpoint rounding not looking great around zero
This commit is contained in:
commit
d6e78e7d95
@ -23,6 +23,12 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
createTest(CreateDistributedHitEvents());
|
createTest(CreateDistributedHitEvents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestManyDistributedEventsOffset()
|
||||||
|
{
|
||||||
|
createTest(CreateDistributedHitEvents(-3.5));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestAroundCentre()
|
public void TestAroundCentre()
|
||||||
{
|
{
|
||||||
|
@ -64,10 +64,22 @@ namespace osu.Game.Screens.Ranking.Statistics
|
|||||||
// Prevent div-by-0 by enforcing a minimum bin size
|
// Prevent div-by-0 by enforcing a minimum bin size
|
||||||
binSize = Math.Max(1, binSize);
|
binSize = Math.Max(1, binSize);
|
||||||
|
|
||||||
|
bool roundUp = true;
|
||||||
|
|
||||||
foreach (var e in hitEvents)
|
foreach (var e in hitEvents)
|
||||||
{
|
{
|
||||||
int binOffset = (int)Math.Round(e.TimeOffset / binSize, MidpointRounding.AwayFromZero);
|
double binOffset = e.TimeOffset / binSize;
|
||||||
bins[timing_distribution_centre_bin_index + binOffset]++;
|
|
||||||
|
// .NET's round midpoint handling doesn't provide a behaviour that works amazingly for display
|
||||||
|
// purposes here. We want midpoint rounding to roughly distribute evenly to each adjacent bucket
|
||||||
|
// so the easiest way is to cycle between downwards and upwards rounding as we process events.
|
||||||
|
if (Math.Abs(binOffset - (int)binOffset) == 0.5)
|
||||||
|
{
|
||||||
|
binOffset = (int)binOffset + Math.Sign(binOffset) * (roundUp ? 1 : 0);
|
||||||
|
roundUp = !roundUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bins[timing_distribution_centre_bin_index + (int)Math.Round(binOffset, MidpointRounding.AwayFromZero)]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxCount = bins.Max();
|
int maxCount = bins.Max();
|
||||||
|
Loading…
Reference in New Issue
Block a user