From a1b206135d64d2a7898512fcd1e272360514ca57 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Thu, 15 Oct 2015 16:10:44 +0200 Subject: Factoring shift calculations --- src/main/java/Seam.java | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/main/java/Seam.java') diff --git a/src/main/java/Seam.java b/src/main/java/Seam.java index 3778f34..88cc245 100644 --- a/src/main/java/Seam.java +++ b/src/main/java/Seam.java @@ -51,31 +51,34 @@ public final class Seam { int[][] graph = new int[matrixSize + 2][]; for (int row = 0; row < height - 1; ++row) { - int shift = (row + 1) * width; + int rowShift = row * width; + int nextRowShift = (row + 1) * width; - graph[row * width] = new int[]{ - shift, - shift + 1, + graph[rowShift] = new int[]{ + nextRowShift, + nextRowShift + 1, }; - graph[row * width + (width - 1)] = new int[]{ - shift + (width - 2), - shift + (width - 1), + graph[rowShift + (width - 1)] = new int[]{ + nextRowShift + (width - 2), + nextRowShift + (width - 1), }; for (int col = 1; col < width - 1; ++col) - graph[row * width + col] = new int[]{ - shift + (col - 1), - shift + (col), - shift + (col + 1), + graph[rowShift + col] = new int[]{ + nextRowShift + (col - 1), + nextRowShift + (col), + nextRowShift + (col + 1), }; } - graph[(matrixSize)] = new int[width]; + graph[matrixSize] = new int[width]; for (int col = 0; col < width; ++col) graph[matrixSize][col] = col; graph[matrixSize + 1] = new int[0]; - for (int col = 0; col < width; ++col) graph[(height - 1) * width + col] = new int[]{matrixSize + 1}; + int rowShift = (height - 1) * width; + for (int col = 0; col < width; ++col) + graph[rowShift + col] = new int[]{matrixSize + 1}; return graph; } -- cgit v1.2.3