diff --git a/osu.Game.Tests/Visual/Matchmaking/TestSceneRatingDistributionGraph.cs b/osu.Game.Tests/Visual/Matchmaking/TestSceneRatingDistributionGraph.cs index b9c2e979a5c9..6f4d9aa9b7dc 100644 --- a/osu.Game.Tests/Visual/Matchmaking/TestSceneRatingDistributionGraph.cs +++ b/osu.Game.Tests/Visual/Matchmaking/TestSceneRatingDistributionGraph.cs @@ -61,6 +61,37 @@ public void TestNoData() AddStep("set empty data", () => graph.SetData([], null)); } + [Test] + public void TestOutOfBoundsUserRating() + { + AddStep("set data with max user rating", () => + { + List<(int x, int y)> values = new List<(int x, int y)>(); + for (int i = 400; i <= 2800; i += 100) + values.Add((i, (int)Math.Round(generateCount(i, 1600, 400, 7200)))); + + graph.SetData(values.ToArray(), 4000); + }); + + AddStep("set data with min user rating", () => + { + List<(int x, int y)> values = new List<(int x, int y)>(); + for (int i = 400; i <= 2800; i += 100) + values.Add((i, (int)Math.Round(generateCount(i, 1600, 400, 7200)))); + + graph.SetData(values.ToArray(), 0); + }); + + AddStep("set data with only user rating", () => + { + List<(int x, int y)> values = new List<(int x, int y)>(); + for (int i = 400; i <= 2800; i += 100) + values.Add((i, (int)Math.Round(generateCount(i, 1600, 400, 7200)))); + + graph.SetData([], 1500); + }); + } + private static double generateCount(double x, double mean, double stdDev, double amplitude) { return amplitude * Math.Exp(-Math.Pow(x - mean, 2) / (2 * Math.Pow(stdDev, 2))) + Random.Shared.Next(300); diff --git a/osu.Game/Screens/OnlinePlay/Matchmaking/Queue/RatingDistributionGraph.cs b/osu.Game/Screens/OnlinePlay/Matchmaking/Queue/RatingDistributionGraph.cs index aba47e959132..d4d4a83eb693 100644 --- a/osu.Game/Screens/OnlinePlay/Matchmaking/Queue/RatingDistributionGraph.cs +++ b/osu.Game/Screens/OnlinePlay/Matchmaking/Queue/RatingDistributionGraph.cs @@ -236,9 +236,21 @@ public void SetData((int x, int y)[] data, int? userRating) data.Zip(data.Skip(1), (a, b) => Math.Abs(b.x - a.x)).DefaultIfEmpty().Min() ); + if (userRating < xRange.min) + { + this.data = this.data.Prepend((userRating.Value, 1)).ToArray(); + xRange.min = userRating.Value; + } + + if (userRating > xRange.max) + { + this.data = this.data.Append((userRating.Value, 1)).ToArray(); + xRange.max = userRating.Value; + } + yRange = ( 0, - (int)roundToSignificant(data.Select(d => d.y).DefaultIfEmpty().Max()) + (int)roundToSignificant(this.data.Select(d => d.y).DefaultIfEmpty().Max()) ); updateGraph();