The following code should print multiple lines of
1
2
3
mixed with lines of
0
However, what it actually prints is multiple lines of
1
1
1
1
3
mixed with lines of
0
Code:
boxes = []
for y in range(len(hmap)):
for x in range(len(hmap[y])):
w = 4
h = 4
minh = hmap[y][x]
maxh = hmap[y][x]
htemp = h
while True:
if y + htemp > len(hmap): break
passes = False
wtemp = w
while True:
if x + wtemp > len(hmap[y]): break
for c in range(x, x+wtemp):
for r in range(y, y+htemp):
minh = min(minh,hmap[c][r])
maxh = max(maxh,hmap[c][r])
if maxh - minh > v:
print('1')
break
else:
print('2')
break
else:
print('3')
break
print('0')
passes = True
wtemp += 1
if passes:
boxes.append([x,y,wtemp-1,htemp])
htemp += 1
if not passes: break
hmap
is a 2D array of float values that is passed to the function this code is in.
This segment of code is supposed to generate a series of rectangles for other (irrelevant) parts of code to use later on. Rectangles that "pass" (min/max values don't have a difference greater than v
) cause
0
to be printed. Rectangles that don't "pass" should cause
1
2
3
to be printed as the nested for
and while
loops break. Why doesn't it work?