Skip to content

Commit 86ecf58

Browse files
add type annotations. add divided method to Mag. simplify __eq__ of Mag
1 parent 2c3b996 commit 86ecf58

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

wkcuber/mag.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from math import log2
33
from functools import total_ordering
44

5+
from typing import List
56

67
@total_ordering
78
class Mag:
@@ -30,11 +31,7 @@ def __lt__(self, other):
3031
return max(self.mag) < (max(other.to_array()))
3132

3233
def __eq__(self, other):
33-
is_equal = True
34-
for m1, m2 in zip(self.mag, other.mag):
35-
if m1 != m2:
36-
is_equal = False
37-
return is_equal
34+
return all(m1 == m2 for m1, m2 in zip(self.mag, other.mag))
3835

3936
def __str__(self):
4037
return self.to_layer_name()
@@ -49,14 +46,17 @@ def to_layer_name(self):
4946
def to_array(self):
5047
return self.mag
5148

52-
def scaled_by(self, factor):
49+
def scaled_by(self, factor: int):
5350
return Mag([mag * factor for mag in self.mag])
5451

55-
def scale_by(self, factor):
52+
def scale_by(self, factor: int):
5653
self.mag = [mag * factor for mag in self.mag]
5754

58-
def divide_by(self, d):
55+
def divided(self, coord: List[int]):
56+
return [ c // m for c, m in zip(coord, self.mag)]
57+
58+
def divide_by(self, d: int):
5959
self.mag = [mag // d for mag in self.mag]
6060

61-
def divided_by(self, d):
61+
def divided_by(self, d: int):
6262
return Mag([mag // d for mag in self.mag])

0 commit comments

Comments
 (0)