Skip to content

Commit

Permalink
add Math.round() to Pixel.correctLevel()
Browse files Browse the repository at this point in the history
The old versions of setRed/Green/Blue cast doubles to ints whenever
necessary. I thought the new versions would, but they actually didn't
because they passed the values through Pixel.correctLevel(int). I
assumed Jython would downcast the doubles to ints, but that was wrong.

So, I added a Pixel.correctLevel(double) that rounds the value passed
in before passing it to Pixel.correctLevel(int).
  • Loading branch information
leafstorm committed Aug 18, 2014
1 parent 87a847e commit 1686d5b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jes/java/Pixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ public static void setWrapLevels (boolean wrap) {
wrapLevels = wrap;
}

/**
* Round and correct a color level to be within 0 and 255,
* according to the current wrapLevels setting.
*
* @param level The user-provided level.
* @return A value within 0 and 255.
*/
public static int correctLevel (double level) {
return correctLevel((int) Math.round(level));
}

/**
* Correct a color level to be within 0 and 255,
* according to the current wrapLevels setting.
Expand Down

0 comments on commit 1686d5b

Please sign in to comment.