From cc970ffd8069ea37b9febe60de15f8041b67b415 Mon Sep 17 00:00:00 2001 From: Valerus9 Date: Fri, 8 Aug 2025 13:41:59 +0200 Subject: [PATCH] Simplify logic of IsInRange() --- osu.Game/Screens/Select/FilterCriteria.cs | 39 ++++++----------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/osu.Game/Screens/Select/FilterCriteria.cs b/osu.Game/Screens/Select/FilterCriteria.cs index 2a301dbcda..c223c291ee 100644 --- a/osu.Game/Screens/Select/FilterCriteria.cs +++ b/osu.Game/Screens/Select/FilterCriteria.cs @@ -154,44 +154,25 @@ namespace osu.Game.Screens.Select public bool IsInRange(T value) { + bool lowerRangeSatisfied = true; + bool upperRangeSatisfied = true; + if (Min != null) { int comparison = Comparer.Default.Compare(value, Min.Value); - - if (comparison < 0 && !InvertRange) - return false; - - if (comparison == 0 && !IsLowerInclusive && !InvertRange) - return false; + lowerRangeSatisfied = comparison > 0 || (comparison == 0 && IsLowerInclusive); } if (Max != null) { int comparison = Comparer.Default.Compare(value, Max.Value); - - if (comparison > 0 && !InvertRange) - return false; - - if (comparison == 0 && !IsUpperInclusive && !InvertRange) - return false; + upperRangeSatisfied = comparison < 0 || (comparison == 0 && IsUpperInclusive); } - if (Min != null && Max != null) - { - int minComparison = Comparer.Default.Compare(value, Min.Value); - int maxComparison = Comparer.Default.Compare(value, Max.Value); - - if (minComparison > 0 && maxComparison < 0 && InvertRange) - return false; - - if (minComparison == 0 && IsLowerInclusive && InvertRange) - return false; - - if (maxComparison == 0 && IsUpperInclusive && InvertRange) - return false; - } - - return true; + bool result = lowerRangeSatisfied && upperRangeSatisfied; + if (InvertRange) + result = !result; + return result; } public T? Min; @@ -199,7 +180,7 @@ namespace osu.Game.Screens.Select public bool IsLowerInclusive; public bool IsUpperInclusive; /// - /// If true, only outside of MaxValue and MinValue will return true; + /// If true, only outside of MaxValue and MinValue will return true /// public bool InvertRange;