Skip to content

Commit ebca57d

Browse files
authored
Move and slightly improve get_points_for_thick_line (#2106)
* Remove drawing_support.py * Move get_points_for_thick_line to draw_commands.py where it belongs * Remove drawing_support.py module * Remove drawing_support.py file and quick index script reference * Stop redoing math in get_points_for_thick_line * Remove reference in manually written API docs file
1 parent 8e01131 commit ebca57d

5 files changed

Lines changed: 41 additions & 48 deletions

File tree

arcade/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def configure_logging(level: Optional[int] = None):
6868
# pyglet.options['win32_gdi_font'] = True
6969

7070
# Imports from modules that don't do anything circular
71-
from .drawing_support import get_points_for_thick_line
7271

7372
# Complex imports with potential circularity
7473
from .window_commands import close_window
@@ -109,6 +108,7 @@ def configure_logging(level: Optional[int] = None):
109108
from .texture import get_default_image
110109
from .texture import get_default_texture
111110

111+
from .draw_commands import get_points_for_thick_line
112112
from .draw_commands import draw_arc_filled
113113
from .draw_commands import draw_arc_outline
114114
from .draw_commands import draw_circle_filled

arcade/draw_commands.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
import pyglet.gl as gl
2020

2121
from arcade.color import WHITE
22-
from arcade.types import AsFloat, Color, RGBA255, PointList, Point, Point2List
22+
from arcade.types import AsFloat, Color, RGBA255, PointList, Point, Point2List, Point2
2323
from arcade.earclip import earclip
2424
from arcade.types.rect import Rect, LBWH, LRBT, XYWH
2525
from .math import rotate_point
2626
from arcade import (
27-
get_points_for_thick_line,
2827
Texture,
2928
get_window,
3029
)
@@ -58,10 +57,49 @@
5857
"draw_scaled_texture_rectangle",
5958
"draw_texture_rectangle",
6059
"draw_lbwh_rectangle_textured",
60+
"get_points_for_thick_line",
6161
"get_pixel",
6262
"get_image"
6363
]
6464

65+
66+
def get_points_for_thick_line(start_x: float, start_y: float,
67+
end_x: float, end_y: float,
68+
line_width: float) -> Tuple[Point2, Point2,
69+
Point2, Point2]:
70+
"""
71+
Function used internally for Arcade. OpenGL draws triangles only, so a thick
72+
line must be two triangles that make up a rectangle. This calculates and returns
73+
those points.
74+
"""
75+
vector_x = start_x - end_x
76+
vector_y = start_y - end_y
77+
perpendicular_x = vector_y
78+
perpendicular_y = -vector_x
79+
length = math.sqrt(vector_x * vector_x + vector_y * vector_y)
80+
if length == 0:
81+
normal_x = 1.0
82+
normal_y = 1.0
83+
else:
84+
normal_x = perpendicular_x / length
85+
normal_y = perpendicular_y / length
86+
87+
half_width = line_width / 2
88+
shift_x = normal_x * half_width
89+
shift_y = normal_y * half_width
90+
91+
r1_x = start_x + shift_x
92+
r1_y = start_y + shift_y
93+
r2_x = start_x - shift_x
94+
r2_y = start_y - shift_y
95+
r3_x = end_x + shift_x
96+
r3_y = end_y + shift_y
97+
r4_x = end_x - shift_x
98+
r4_y = end_y - shift_y
99+
100+
return (r1_x, r1_y), (r2_x, r2_y), (r4_x, r4_y), (r3_x, r3_y)
101+
102+
65103
# --- BEGIN ARC FUNCTIONS # # #
66104

67105

arcade/drawing_support.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

doc/api_docs/arcade.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ for the Python Arcade library. See also:
1616
api/types
1717
api/drawing_primitives
1818
api/drawing_batch
19-
api/drawing_utilities
2019
api/sprites
2120
api/sprite_list
2221
api/sprite_scenes

util/update_quick_index.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
'application.py': ['Window and View', 'window.rst'],
1717
'shape_list.py': ['Shape Lists', 'drawing_batch.rst'],
1818
'context.py': ['OpenGL Context', 'open_gl.rst'],
19-
'drawing_support.py': ['Drawing - Utility', 'drawing_utilities.rst'],
2019
'draw_commands.py': ['Drawing - Primitives', 'drawing_primitives.rst'],
2120
'geometry.py': ['Geometry Support', 'geometry.rst'],
2221
'isometric.py': ['Isometric Map Support (incomplete)', 'isometric.rst'],

0 commit comments

Comments
 (0)