Skip to content

Commit 2d349f4

Browse files
committed
Optimize draw_rect_outline by reducing dot access
* Reduce dot access by fetching values once * Add inline diagram of the rectangle points
1 parent e5962e3 commit 2d349f4

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

arcade/draw/rect.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,46 @@ def draw_rect_outline(
207207
HALF_BORDER = border_width / 2
208208

209209
# fmt: off
210-
i_lb = rect.bottom_left.x + HALF_BORDER, rect.bottom_left.y + HALF_BORDER
211-
i_rb = rect.bottom_right.x - HALF_BORDER, rect.bottom_right.y + HALF_BORDER
212-
i_rt = rect.top_right.x - HALF_BORDER, rect.top_right.y - HALF_BORDER
213-
i_lt = rect.top_left.x + HALF_BORDER, rect.top_left.y - HALF_BORDER
214-
o_lb = rect.bottom_left.x - HALF_BORDER, rect.bottom_left.y - HALF_BORDER
215-
o_rb = rect.bottom_right.x + HALF_BORDER, rect.bottom_right.y - HALF_BORDER
216-
o_rt = rect.top_right.x + HALF_BORDER, rect.top_right.y + HALF_BORDER
217-
o_lt = rect.top_left.x - HALF_BORDER, rect.top_right.y + HALF_BORDER
210+
left = rect.left
211+
right = rect.right
212+
bottom = rect.bottom
213+
top = rect.top
214+
x = rect.x
215+
y = rect.y
216+
217+
# o = outer, i = inner
218+
#
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
218242
# fmt: on
219243

220244
point_list: PointList = (o_lt, i_lt, o_rt, i_rt, o_rb, i_rb, o_lb, i_lb, o_lt, i_lt)
221245

222246
if tilt_angle != 0:
223247
point_list_2 = []
224248
for point in point_list:
225-
new_point = rotate_point(point[0], point[1], rect.x, rect.y, tilt_angle)
249+
new_point = rotate_point(point[0], point[1], x, y, tilt_angle)
226250
point_list_2.append(new_point)
227251
point_list = point_list_2
228252

0 commit comments

Comments
 (0)