]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Improved output distribution of RoundToLevels (#25026)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 7 Feb 2024 23:37:24 +0000 (18:37 -0500)
committerGitHub <noreply@github.com>
Wed, 7 Feb 2024 23:37:24 +0000 (10:37 +1100)
* Improved output distribution of RoundToLevels

* Updated tests

* Oops

Content.Shared/Rounding/ContentHelpers.cs
Content.Tests/Shared/Utility/ContentHelpers_Test.cs

index b1525ed4ee658ebffd61be9153737cb9a1302f40..9ecee22998b8c311f50003f3d8fbe5c65b88045d 100644 (file)
             }
 
             var toOne = actual / max;
-            double threshold;
-            if (levels % 2 == 0)
-            {
-                // Basically, if we have an even count of levels, there's no exact "mid point".
-                // Thus, I nominate the first one below the 50% mark.
-                threshold = ((levels / 2f) - 1) / (levels - 1);
-            }
-            else
-            {
-                threshold = 0.5f;
-            }
-
-            var preround = toOne * (levels - 1);
-            if (toOne < threshold || levels <= 2)
-            {
-                return (int) Math.Ceiling(preround);
-            }
-            else
-            {
-                return (int) Math.Floor(preround);
-            }
+            return (int) Math.Ceiling(toOne * (levels - 2));
         }
 
         /// <summary>
index 52d4286b8ceae5c4a1a654bcc2d1b370f9bfe25b..6a546238922c0a16588baaa787b575bfd60b4688 100644 (file)
@@ -18,15 +18,15 @@ namespace Content.Tests.Shared.Utility
                 (0.01f, 10, 5, 1),
                 (1, 10, 5, 1),
                 (2, 10, 5, 1),
-                (2.5f, 10, 5, 1),
-                (2.51f, 10, 5, 2),
-                (3, 10, 5, 2),
+                (3, 10, 5, 1),
+                (3.33f, 10, 5, 1),
+                (3.34f, 10, 5, 2),
                 (4, 10, 5, 2),
                 (5, 10, 5, 2),
                 (6, 10, 5, 2),
-                (7, 10, 5, 2),
-                (7.49f, 10, 5, 2),
-                (7.5f, 10, 5, 3),
+                (6.66f, 10, 5, 2),
+                (6.67f, 10, 5, 3),
+                (7, 10, 5, 3),
                 (8, 10, 5, 3),
                 (9, 10, 5, 3),
                 (10, 10, 5, 4),