Skip to content

Commit

Permalink
Fix the scale method (#72401)
Browse files Browse the repository at this point in the history
  • Loading branch information
cytrek-betoniarek committed Dec 4, 2023
1 parent cacd03b commit ec0c0dd
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public static int scale(int oldmax, int newmax, int value) {
if (value == PRIORITY_USE_DEFAULT_PRIORITY) {
return PRIORITY_USE_DEFAULT_PRIORITY;
}
float eps = (float)0.0001;
float p = ((float) (value - 1) / (float) (oldmax - 1));
if(p*(newmax - 1) > Math.round(p*(newmax - 1))-eps && p*(newmax - 1) < Math.round(p*(newmax - 1))+eps){
return (int) (Math.round(p * (newmax - 1))) + 1;
}
if (p <= 0.5) {
return (int) (Math.floor(p * (newmax - 1))) + 1;
}
Expand Down

0 comments on commit ec0c0dd

Please sign in to comment.