Allow comparison between Position and Tuple

Fixes longstanding type error.
This commit is contained in:
Arjan Molenaar 2020-11-17 11:03:25 +01:00
parent 7d3b8fcec3
commit c787d1408f
2 changed files with 9 additions and 0 deletions

View File

@ -58,6 +58,9 @@ class Position:
def __eq__(self, other):
return isinstance(other, Position) and self.x == other.x and self.y == other.y
def __lt__(self, other):
return self[0] < other[0] and self[1] < other[1]
class MatrixProjection(Constraint):
def __init__(self, pos: Position, matrix: Matrix):

View File

@ -17,6 +17,12 @@ def test_position(position):
assert position[1] == pos.y
def test_position_can_compare_with_tuple():
pos = Position(3, 3)
assert pos < (4, 4)
def test_matrix_projection_exposes_variables():
proj = MatrixProjection(Position(0, 0), Matrix())