@@ -205,6 +205,7 @@ def draw_rect_outline(
205205 """
206206
207207 HALF_BORDER = border_width / 2
208+ # Extremely unrolled code below
208209
209210 # fmt: off
210211 left = rect .left
@@ -216,40 +217,56 @@ def draw_rect_outline(
216217
217218 # o = outer, i = inner
218219 #
219- # o_lt o_rt
220- # +-------------------------------+
221- # | i_lt i_rt |
222- # | +---------------------+ |
223- # | | | |
224- # | | | |
225- # | | | |
226- # | +---------------------+ |
227- # | i_lb i_rb |
228- # +-------------------------------+
229- # o_lb o_rb
230-
231- # Inner vertices
232- i_lb = left + HALF_BORDER , bottom + HALF_BORDER
233- i_rb = right - HALF_BORDER , bottom + HALF_BORDER
234- i_rt = right - HALF_BORDER , top - HALF_BORDER
235- i_lt = left + HALF_BORDER , top - HALF_BORDER
236-
237- # Outer vertices
238- o_lb = left - HALF_BORDER , bottom - HALF_BORDER
239- o_rb = right + HALF_BORDER , bottom - HALF_BORDER
240- o_rt = right + HALF_BORDER , top + HALF_BORDER
241- o_lt = left - HALF_BORDER , top + HALF_BORDER
220+ # o_left, o_top o_right, o_top
221+ # +----------------------------------------+
222+ # | i_left, i_top i_right, i_top |
223+ # | +----------------------------------+ |
224+ # | | | |
225+ # | | | |
226+ # | | | |
227+ # | +----------------------------------+ |
228+ # | i_left, i_bottom i_right , i_bottom |
229+ # +----------------------------------------+
230+ # o_left, o_bottom o_right, o_bottom
231+
232+ i_left = left + HALF_BORDER
233+ i_bottom = bottom + HALF_BORDER
234+ i_right = right - HALF_BORDER
235+ i_top = top - HALF_BORDER
236+
237+ o_left = left - HALF_BORDER
238+ o_bottom = bottom - HALF_BORDER
239+ o_right = right + HALF_BORDER
240+ o_top = top + HALF_BORDER
241+
242+ # This is intentionally unrolled to minimize repacking tuples
243+ if tilt_angle == 0 :
244+ point_list : PointList = (
245+ (o_left , o_top ),
246+ (i_left , i_top ),
247+ (o_right , o_top ),
248+ (i_right , i_top ),
249+ (o_right , o_bottom ),
250+ (i_right , i_bottom ),
251+ (o_left , o_bottom ),
252+ (i_left , i_bottom ),
253+ (o_left , i_top ),
254+ (i_left , i_top )
255+ )
256+ else :
257+ point_list : PointList = (
258+ rotate_point (o_left , o_top , x , y , tilt_angle ),
259+ rotate_point (i_left , i_top , x , y , tilt_angle ),
260+ rotate_point (o_right , o_top , x , y , tilt_angle ),
261+ rotate_point (i_right , i_top , x , y , tilt_angle ),
262+ rotate_point (o_right , o_bottom , x , y , tilt_angle ),
263+ rotate_point (i_right , i_bottom , x , y , tilt_angle ),
264+ rotate_point (o_left , o_bottom , x , y , tilt_angle ),
265+ rotate_point (i_left , i_bottom , x , y , tilt_angle ),
266+ rotate_point (o_left , i_top , x , y , tilt_angle ),
267+ rotate_point (i_left , i_top , x , y , tilt_angle )
268+ )
242269 # fmt: on
243-
244- point_list : PointList = (o_lt , i_lt , o_rt , i_rt , o_rb , i_rb , o_lb , i_lb , o_lt , i_lt )
245-
246- if tilt_angle != 0 :
247- point_list_2 = []
248- for point in point_list :
249- new_point = rotate_point (point [0 ], point [1 ], x , y , tilt_angle )
250- point_list_2 .append (new_point )
251- point_list = point_list_2
252-
253270 _generic_draw_line_strip (point_list , color , gl .TRIANGLE_STRIP )
254271
255272
0 commit comments