Skip to content

Commit

Permalink
Add Vector.zero as a class-level constant
Browse files Browse the repository at this point in the history
  • Loading branch information
nbraud committed Oct 23, 2021
1 parent 41e447a commit 8e1ed05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ppb_vector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class Vector:
x: float
y: float

# Class-level attributes
zero: typing.ClassVar['Vector']

# Tell CPython that this isn't an extendable dict
__slots__ = ('x', 'y', '__weakref__')

Expand Down Expand Up @@ -555,4 +558,7 @@ def reflect(self, surface_normal: VectorLike) -> 'Vector':
return self - (2 * (self * surface_normal) * surface_normal)


Vector.zero = Vector(0, 0)


Sequence.register(Vector)
5 changes: 5 additions & 0 deletions tests/test_zero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ppb_vector import Vector


def test_zero():
assert not Vector.zero

0 comments on commit 8e1ed05

Please sign in to comment.