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 Jun 1, 2019
1 parent 304e0bd commit 1eca758
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 @@ -60,6 +60,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 @@ -527,4 +530,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 1eca758

Please sign in to comment.