Skip to content

Commit

Permalink
Merge pull request #5 from jos-rosenqvist-3812/getpixel-require
Browse files Browse the repository at this point in the history
Improve getPixel error handling
  • Loading branch information
bjornregnell authored Sep 10, 2019
2 parents bd7b383 + 6f6e1d7 commit 51f9f25
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/scala/introprog/PixelWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ class PixelWindow(
}

/** Return the color of the pixel at `(x, y)`. */
def getPixel(x: Int, y: Int): java.awt.Color = Swing.await {
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")
Swing.await { new java.awt.Color(canvas.img.getRGB(x, y)) }
}

/** Show the window. Has no effect if the window is already visible. */
Expand Down

0 comments on commit 51f9f25

Please sign in to comment.