Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0e1b91f

Browse files
committed
Added reading sort for complex utilities
1 parent2d32839 commit0e1b91f

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+
frommathimportsqrt
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
elifmode=="yx":
6363
complexes.sort(key=lambdaa: (a.imag,a.real))
64+
# Sorts by negative imaginary, then by real component (-y then x) - 'Reading" order
65+
elifmode=="reading":
66+
complexes.sort(key=lambdaa: (-a.imag,a.real))
6467
# Sorts by distance from 0,0 (kind of polar coordinates)
6568
else:
6669
complexes.sort(key=lambdaa:sqrt(a.imag**2+a.real**2))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp