Skip to content

Commit d6e7dbe

Browse files
committedNov 7, 2021
backport fix for issue #120 and tests
1 parent beef941 commit d6e7dbe

File tree

15 files changed

+122
-8
lines changed

15 files changed

+122
-8
lines changed
 

‎pcbasic/graphics.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -545,18 +545,18 @@ def paint(self, lcoord, pattern, c, border, background):
545545
# check next scanlines and add intervals to the list
546546
if ydir == 0:
547547
if y + 1 <= bound_y1:
548-
line_seed = self.check_scanline(line_seed, x_left, x_right, y+1, c, tile, back, border, 1)
548+
line_seed = self.check_scanline(line_seed, x_left, x_right, y+1, c, tile, solid, back, border, 1)
549549
if y - 1 >= bound_y0:
550-
line_seed = self.check_scanline(line_seed, x_left, x_right, y-1, c, tile, back, border, -1)
550+
line_seed = self.check_scanline(line_seed, x_left, x_right, y-1, c, tile, solid, back, border, -1)
551551
else:
552552
# check the same interval one scanline onward in the same direction
553553
if y+ydir <= bound_y1 and y+ydir >= bound_y0:
554-
line_seed = self.check_scanline(line_seed, x_left, x_right, y+ydir, c, tile, back, border, ydir)
554+
line_seed = self.check_scanline(line_seed, x_left, x_right, y+ydir, c, tile, solid, back, border, ydir)
555555
# check any bit of the interval that was extended one scanline backward
556556
# this is where the flood fill goes around corners.
557557
if y-ydir <= bound_y1 and y-ydir >= bound_y0:
558-
line_seed = self.check_scanline(line_seed, x_left, x_start-1, y-ydir, c, tile, back, border, -ydir)
559-
line_seed = self.check_scanline(line_seed, x_stop+1, x_right, y-ydir, c, tile, back, border, -ydir)
558+
line_seed = self.check_scanline(line_seed, x_left, x_start-1, y-ydir, c, tile, solid, back, border, -ydir)
559+
line_seed = self.check_scanline(line_seed, x_stop+1, x_right, y-ydir, c, tile, solid, back, border, -ydir)
560560
# draw the pixels for the current interval
561561
if solid:
562562
self.screen.fill_interval(x_left, x_right, y, tile[0][0])
@@ -569,7 +569,7 @@ def paint(self, lcoord, pattern, c, border, background):
569569
self.last_attr = c
570570

571571
def check_scanline(self, line_seed, x_start, x_stop, y,
572-
c, tile, back, border, ydir):
572+
c, tile, is_solid, back, border, ydir):
573573
""" Append all subintervals between border colours to the scanning stack. """
574574
if x_stop < x_start:
575575
return line_seed
@@ -584,8 +584,10 @@ def check_scanline(self, line_seed, x_start, x_stop, y,
584584
pattern = self.screen.get_until(x, x_stop+1, y, border)
585585
x_stop_next = x + len(pattern) - 1
586586
x = x_stop_next + 1
587-
# never match zero pattern (special case)
588-
has_same_pattern = (rtile != [0]*8)
587+
# don't match zero row unless pattern is solid (special case)
588+
# - avoid breaking off pattern filling on zero rows
589+
# - but also don't loop forever on solid background fills
590+
has_same_pattern = (is_solid or rtile != [0]*8)
589591
for pat_x in range(len(pattern)):
590592
if not has_same_pattern:
591593
break
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=freedos
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1 ' related to bug https://github.com/robhagemans/pcbasic/issues/120
2+
2 ' test pattern fill with one row completely empty (e.g. equal to background)
3+
3 ' flood fill should not stop on this row
4+
4 ' despite fix for issue #120
5+
10 SCREEN 1:CLS
6+
20 CIRCLE(150,150),20
7+
30 PAINT(150,150),CHR$(&H80)+CHR$(&H0)+CHR$(&H70)
8+
35 ' should be 1 (part of pattern) not 0 (background)
9+
40 ATTR = POINT(148, 161)
10+
50 OPEN "OUTPUT.TXT" FOR OUTPUT AS 1
11+
60 PRINT#1, ATTR
12+
70 CLOSE
13+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=freedos
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1 ' related to bug https://github.com/robhagemans/pcbasic/issues/120
2+
2 ' test pattern fill with one row completely empty (e.g. equal to background)
3+
3 ' flood fill should not stop on this row
4+
4 ' despite fix for issue #120
5+
10 SCREEN 1:CLS
6+
20 CIRCLE(150,150),20
7+
30 PAINT(150,150),CHR$(&H80)+CHR$(&H0)+CHR$(&H70)
8+
35 ' should be 1 (part of pattern) not 0 (background)
9+
40 ATTR = POINT(148, 161)
10+
50 OPEN "OUTPUT.TXT" FOR OUTPUT AS 1
11+
60 PRINT#1, ATTR
12+
70 CLOSE
13+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=freedos
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1 ' test for bug https://github.com/robhagemans/pcbasic/issues/120
2+
2 ' a successful test finishes
3+
3 ' bug behaviour is to hang on the flood fill
4+
5 ' test case provided by mrclay
5+
10 SCREEN 1:CLS
6+
20 CIRCLE(15,15),4,1
7+
30 PSET(16,16),1
8+
40 PAINT(13,14),3,1
9+
50 LOCATE 5: PRINT "You should see 'PASS!'"
10+
60 'LOCATE 6: INPUT "after hitting Enter...", F
11+
70 PAINT(13,14),0,1
12+
80 PRINT "PASS!"
13+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=freedos
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1 ' test for bug https://github.com/robhagemans/pcbasic/issues/120
2+
2 ' a successful test finishes
3+
3 ' bug behaviour is to hang on the flood fill
4+
5 ' test case provided by mrclay
5+
10 SCREEN 1:CLS
6+
20 CIRCLE(15,15),4,1
7+
30 PSET(16,16),1
8+
40 PAINT(13,14),3,1
9+
50 LOCATE 5: PRINT "You should see 'PASS!'"
10+
60 'LOCATE 6: INPUT "after hitting Enter...", F
11+
70 PAINT(13,14),0,1
12+
80 PRINT "PASS!"
13+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=freedos
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1 ' test pattern flood fill with solid rows in a non-background attribute
2+
2 ' unlike with background atribute 0, here the pattern fill breaks off after one row
3+
5 CLS
4+
10 SCREEN 1
5+
20 CIRCLE(100,100),50,2
6+
30 PAINT(100,100),2
7+
40 PAINT (100,100),CHR$(0)+CHR$(&HAA),2
8+
50 PAINT (100,100),CHR$(&HAA)+CHR$(0),2
9+
60 ATTR = POINT(100,102)
10+
100 OPEN "OUTPUT.TXT" FOR OUTPUT AS 1
11+
110 PRINT#1, ATTR
12+
120 CLOSE
13+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2
2+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=freedos
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1 ' test pattern flood fill with solid rows in a non-background attribute
2+
2 ' unlike with background atribute 0, here the pattern fill breaks off after one row
3+
5 CLS
4+
10 SCREEN 1
5+
20 CIRCLE(100,100),50,2
6+
30 PAINT(100,100),2
7+
40 PAINT (100,100),CHR$(0)+CHR$(&HAA),2
8+
50 PAINT (100,100),CHR$(&HAA)+CHR$(0),2
9+
60 ATTR = POINT(100,102)
10+
100 OPEN "OUTPUT.TXT" FOR OUTPUT AS 1
11+
110 PRINT#1, ATTR
12+
120 CLOSE
13+


0 commit comments

Comments
 (0)