From affd57392742e4d04139c1757bb79398a443eacf Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 10 Oct 2015 17:26:48 +0200 Subject: Implement array boundaries access --- src/main/java/Filter.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/Filter.java b/src/main/java/Filter.java index ddc3e92..73b435b 100644 --- a/src/main/java/Filter.java +++ b/src/main/java/Filter.java @@ -13,8 +13,16 @@ public final class Filter { * @return nearest valid pixel color */ public static float at(float[][] gray, int row, int col) { - // TODO at - return 0.0f; + int maxRow = gray.length - 1; + int maxCol = gray[0].length - 1; + + if (row < 0) row = 0; + if (col < 0) col = 0; + + if (row > maxRow) row = maxRow; + if (col > maxCol) col = maxCol; + + return gray[row][col]; } /** -- cgit v1.2.3