aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-10-15 16:10:44 +0200
committerPacien TRAN-GIRARD2015-10-15 16:10:44 +0200
commita1b206135d64d2a7898512fcd1e272360514ca57 (patch)
treed4aaaa22356b216ce7315ce78747ff4a3edfd8f4 /src/main
parent83779ce640236f3198a58ded18e58d419833b5a4 (diff)
downloadseam-stitcher-a1b206135d64d2a7898512fcd1e272360514ca57.tar.gz
Factoring shift calculations
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/Seam.java29
1 files changed, 16 insertions, 13 deletions
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 {
51 int[][] graph = new int[matrixSize + 2][]; 51 int[][] graph = new int[matrixSize + 2][];
52 52
53 for (int row = 0; row < height - 1; ++row) { 53 for (int row = 0; row < height - 1; ++row) {
54 int shift = (row + 1) * width; 54 int rowShift = row * width;
55 int nextRowShift = (row + 1) * width;
55 56
56 graph[row * width] = new int[]{ 57 graph[rowShift] = new int[]{
57 shift, 58 nextRowShift,
58 shift + 1, 59 nextRowShift + 1,
59 }; 60 };
60 61
61 graph[row * width + (width - 1)] = new int[]{ 62 graph[rowShift + (width - 1)] = new int[]{
62 shift + (width - 2), 63 nextRowShift + (width - 2),
63 shift + (width - 1), 64 nextRowShift + (width - 1),
64 }; 65 };
65 66
66 for (int col = 1; col < width - 1; ++col) 67 for (int col = 1; col < width - 1; ++col)
67 graph[row * width + col] = new int[]{ 68 graph[rowShift + col] = new int[]{
68 shift + (col - 1), 69 nextRowShift + (col - 1),
69 shift + (col), 70 nextRowShift + (col),
70 shift + (col + 1), 71 nextRowShift + (col + 1),
71 }; 72 };
72 } 73 }
73 74
74 graph[(matrixSize)] = new int[width]; 75 graph[matrixSize] = new int[width];
75 for (int col = 0; col < width; ++col) graph[matrixSize][col] = col; 76 for (int col = 0; col < width; ++col) graph[matrixSize][col] = col;
76 77
77 graph[matrixSize + 1] = new int[0]; 78 graph[matrixSize + 1] = new int[0];
78 for (int col = 0; col < width; ++col) graph[(height - 1) * width + col] = new int[]{matrixSize + 1}; 79 int rowShift = (height - 1) * width;
80 for (int col = 0; col < width; ++col)
81 graph[rowShift + col] = new int[]{matrixSize + 1};
79 82
80 return graph; 83 return graph;
81 } 84 }