Skip to content

Commit

Permalink
Unprotect _EMPTY_POINT_LIST & move it to arcade.types (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushfoo committed May 29, 2023
1 parent 809dbe3 commit d58d998
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 2 additions & 9 deletions arcade/hitbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@

from PIL.Image import Image

from arcade.types import Point, PointList

from arcade.types import Point, PointList, EMPTY_POINT_LIST

__all__ = ["HitBoxAlgorithm", "HitBox", "RotatableHitBox"]


# Speed / typing workaround:
# 1. Eliminate extra allocations
# 2. Allows HitBox & subclass typing annotation to work cleanly
_EMPTY_POINT_LIST: PointList = tuple()


class HitBoxAlgorithm:
"""
The base class for hit box algorithms.
Expand Down Expand Up @@ -99,7 +92,7 @@ def __init__(

# This empty tuple will be replaced the first time
# get_adjusted_points is called
self._adjusted_points: PointList = _EMPTY_POINT_LIST
self._adjusted_points: PointList = EMPTY_POINT_LIST
self._adjusted_cache_dirty = True

@property
Expand Down
10 changes: 10 additions & 0 deletions arcade/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Module specifying data custom types used for type hinting.
"""
from __future__ import annotations

from array import array
import ctypes
import random
Expand Down Expand Up @@ -56,6 +58,7 @@
"PathOrTexture",
"Point",
"PointList",
"EMPTY_POINT_LIST",
"NamedPoint",
"Rect",
"RectList",
Expand Down Expand Up @@ -421,7 +424,14 @@ def random(
Vector = Point
NamedPoint = namedtuple("NamedPoint", ["x", "y"])


PointList = Sequence[Point]
# Speed / typing workaround:
# 1. Eliminate extra allocations
# 2. Allows type annotation to be cleaner, primarily for HitBox & subclasses
EMPTY_POINT_LIST: PointList = tuple()


Rect = Union[Tuple[int, int, int, int], List[int]] # x, y, width, height
RectList = Union[Tuple[Rect, ...], List[Rect]]
FloatRect = Union[Tuple[float, float, float, float], List[float]] # x, y, width, height
Expand Down

0 comments on commit d58d998

Please sign in to comment.