Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e1b91f

Browse files
committed
Added reading sort for complex utilities
1 parent 2d32839 commit 0e1b91f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

2018/complex_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Small library for complex numbers
33
"""
4-
4+
from math import sqrt
55

66
# Cardinal directions
77
north = 1j
@@ -61,6 +61,9 @@ def complex_sort(complexes, mode=""):
6161
# Sorts by imaginary, then by real component (y then x)
6262
elif mode == "yx":
6363
complexes.sort(key=lambda a: (a.imag, a.real))
64+
# Sorts by negative imaginary, then by real component (-y then x) - 'Reading" order
65+
elif mode == "reading":
66+
complexes.sort(key=lambda a: (-a.imag, a.real))
6467
# Sorts by distance from 0,0 (kind of polar coordinates)
6568
else:
6669
complexes.sort(key=lambda a: sqrt(a.imag ** 2 + a.real ** 2))

0 commit comments

Comments
 (0)