@@ -73,46 +73,32 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None):
73
73
y0 , y1 = y1 , y0
74
74
x0 , x1 = x1 , x0
75
75
76
- smallest_x = x0
77
- largest_x = x0
78
-
79
76
# 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
92
79
height = y2 - y0 + 1
93
- width = largest_x - smallest_x + 1
94
80
95
81
self ._palette = displayio .Palette (3 )
96
82
self ._palette .make_transparent (0 )
97
83
self ._bitmap = displayio .Bitmap (width , height , 3 )
98
84
99
85
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 )
101
87
self ._palette [2 ] = fill
102
88
else :
103
89
self ._palette .make_transparent (2 )
104
90
105
91
if outline is not None :
106
92
print ("outline" )
107
93
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 )
111
97
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 )
113
99
114
100
# 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 ):
116
102
if y0 == y2 : # Handle awkward all-on-same-line case as its own thing
117
103
a = x0
118
104
b = x0
0 commit comments