@@ -73,46 +73,32 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None):
7373 y0 , y1 = y1 , y0
7474 x0 , x1 = x1 , x0
7575
76- smallest_x = x0
77- largest_x = x0
78-
7976 # Find the largest and smallest X values to figure out width for bitmap
80- if x1 > largest_x :
81- largest_x = x1
82-
83- if x1 < smallest_x :
84- smallest_x = x1
85-
86- if x2 > largest_x :
87- largest_x = x2
88-
89- if x2 < smallest_x :
90- smallest_x = x2
91-
77+ xs = [x0 , x1 , x2 ]
78+ width = max (xs ) - min (xs ) + 1
9279 height = y2 - y0 + 1
93- width = largest_x - smallest_x + 1
9480
9581 self ._palette = displayio .Palette (3 )
9682 self ._palette .make_transparent (0 )
9783 self ._bitmap = displayio .Bitmap (width , height , 3 )
9884
9985 if fill is not None :
100- self ._helper (x0 - smallest_x , 0 , x1 - smallest_x , y1 - y0 , x2 - smallest_x , y2 - y0 )
86+ self ._draw_filled (x0 - min ( xs ) , 0 , x1 - min ( xs ) , y1 - y0 , x2 - min ( xs ) , y2 - y0 )
10187 self ._palette [2 ] = fill
10288 else :
10389 self ._palette .make_transparent (2 )
10490
10591 if outline is not None :
10692 print ("outline" )
10793 self ._palette [1 ] = outline
108- self ._line (x0 - smallest_x , 0 , x1 - smallest_x , y1 - y0 , 1 )
109- self ._line (x1 - smallest_x , y1 - y0 , x2 - smallest_x , y2 - y0 , 1 )
110- self ._line (x2 - smallest_x , y2 - y0 , x0 - smallest_x , 0 , 1 )
94+ self ._line (x0 - min ( xs ) , 0 , x1 - min ( xs ) , y1 - y0 , 1 )
95+ self ._line (x1 - min ( xs ) , y1 - y0 , x2 - min ( xs ) , y2 - y0 , 1 )
96+ self ._line (x2 - min ( xs ) , y2 - y0 , x0 - min ( xs ) , 0 , 1 )
11197
112- super ().__init__ (self ._bitmap , pixel_shader = self ._palette , x = smallest_x , y = y0 )
98+ super ().__init__ (self ._bitmap , pixel_shader = self ._palette , x = min ( xs ) , y = y0 )
11399
114100 # pylint: disable=invalid-name, too-many-locals, too-many-branches
115- def _helper (self , x0 , y0 , x1 , y1 , x2 , y2 ):
101+ def _draw_filled (self , x0 , y0 , x1 , y1 , x2 , y2 ):
116102 if y0 == y2 : # Handle awkward all-on-same-line case as its own thing
117103 a = x0
118104 b = x0
0 commit comments