We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents bd7b383 + 6f6e1d7 commit 51f9f25Copy full SHA for 51f9f25
src/main/scala/introprog/PixelWindow.scala
@@ -200,8 +200,9 @@ class PixelWindow(
200
}
201
202
/** Return the color of the pixel at `(x, y)`. */
203
- def getPixel(x: Int, y: Int): java.awt.Color = Swing.await {
204
- new java.awt.Color(canvas.img.getRGB(x, y))
+ def getPixel(x: Int, y: Int): java.awt.Color = {
+ require(x >= 0 && x < width && y >= 0 && y < width, "Tried to read a pixel outside the window")
205
+ Swing.await { new java.awt.Color(canvas.img.getRGB(x, y)) }
206
207
208
/** Show the window. Has no effect if the window is already visible. */
0 commit comments