We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d32839 commit 0e1b91fCopy full SHA for 0e1b91f
2018/complex_utils.py
@@ -1,7 +1,7 @@
1
"""
2
Small library for complex numbers
3
4
-
+from math import sqrt
5
6
# Cardinal directions
7
north = 1j
@@ -61,6 +61,9 @@ def complex_sort(complexes, mode=""):
61
# Sorts by imaginary, then by real component (y then x)
62
elif mode == "yx":
63
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))
67
# Sorts by distance from 0,0 (kind of polar coordinates)
68
else:
69
complexes.sort(key=lambda a: sqrt(a.imag ** 2 + a.real ** 2))
0 commit comments