Skip to content

Commit 3d173f2

Browse files
committed
refactor(nearestNeighbor): Remove unnecessary conditional
1 parent 70a70bc commit 3d173f2

1 file changed

Lines changed: 7 additions & 27 deletions

File tree

processor/processor.go

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,37 +142,17 @@ func nearestNeighbor(pImg *[][]color.Color, factor float32) {
142142
return
143143
}
144144

145-
var proportion int
146-
var rows int
147-
var cols int
148-
149-
if factor <= 1 {
150-
proportion = int(1 / factor)
151-
rows = int(len(img) / proportion)
152-
cols = int(len(img[0]) / proportion)
153-
} else {
154-
proportion = int(1 * factor)
155-
rows = int(len(img) * proportion)
156-
cols = int(len(img[0]) * proportion)
157-
}
145+
proportion := int(1 / factor)
146+
rows := int(len(img) / proportion)
147+
cols := int(len(img[0]) / proportion)
158148

159149
res := make([][]color.Color, rows)
160150

161-
if factor <= 1 {
162-
for i := 0; i < rows; i++ {
163-
res[i] = make([]color.Color, cols)
164-
165-
for j := 0; j < cols; j++ {
166-
res[i][j] = img[i*proportion][j*proportion]
167-
}
168-
}
169-
} else {
170-
for i := 0; i < rows; i++ {
171-
res[i] = make([]color.Color, cols)
151+
for i := 0; i < rows; i++ {
152+
res[i] = make([]color.Color, cols)
172153

173-
for j := 0; j < cols; j++ {
174-
res[i][j] = img[i/proportion][j/proportion]
175-
}
154+
for j := 0; j < cols; j++ {
155+
res[i][j] = img[i*proportion][j*proportion]
176156
}
177157
}
178158

0 commit comments

Comments
 (0)