@@ -13,8 +13,8 @@ class Coord(NamedTuple):
1313 it to the x and y values individually.
1414
1515 param:
16- x: float -- X position.
17- y: float -- Y position.
16+ x: int -- X position.
17+ y: int -- Y position.
1818
1919 example::
2020
@@ -27,6 +27,11 @@ class Coord(NamedTuple):
2727 c1 + 1 # 1 is cast to Coord(1, 1)
2828 >>> Coord(2, 2)
2929 ```
30+
31+ note:
32+
33+ True divide `round`s in order to remain compatible with tkinter
34+ coordinate values (`int`).
3035 """
3136
3237 x : int
@@ -43,12 +48,24 @@ def __apply(self, op: Callable, other: Coord.Operand) -> Coord:
4348 return Coord (x , y )
4449
4550 def midpoint (self , other : Coord ) -> Coord :
46- return (self + other ) // 2
51+ """
52+ The Coord that is equal distance from `self` and `other`.
53+
54+ param:
55+ other: Coord -- The point to consider.
56+
57+ return:
58+ Coord -- The resulting coordinate.
59+ """
60+ return (self + other ) / 2
61+
62+ def __truediv__ (self , other ):
63+ result = self .__apply (operator .truediv , other )
64+ return Coord (* map (round , result ))
4765
4866 __add__ = partialmethod (__apply , operator .add )
4967 __sub__ = partialmethod (__apply , operator .sub )
5068 __mul__ = partialmethod (__apply , operator .mul )
5169 __mod__ = partialmethod (__apply , operator .mod )
5270 __pow__ = partialmethod (__apply , operator .pow )
53- __truediv__ = partialmethod (__apply , operator .truediv )
5471 __floordiv__ = partialmethod (__apply , operator .floordiv )
0 commit comments