File tree 1 file changed +7
-10
lines changed
contents/graham_scan/code/nim
1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 1
- from algorithm import sorted
1
+ from algorithm import sort, sorted
2
2
from math import arctan2
3
3
from sequtils import deduplicate, map, toSeq
4
4
import sugar
@@ -21,15 +21,12 @@ proc flipped_point_cmp(pa, pb: Point): int =
21
21
22
22
proc graham_scan (gift: seq [Point ]): seq [Point ] =
23
23
assert (gift.len >= 3 )
24
- let
25
- gift_without_duplicates = sorted (deduplicate (gift), flipped_point_cmp)
26
- pivot = gift_without_duplicates[0 ]
27
- var
28
- points = sorted (gift_without_duplicates[1 ..^ 1 ],
29
- proc (pa, pb: Point ): int =
30
- if polar_angle (pivot, pa) < polar_angle (pivot, pb): - 1
31
- else : 1 )
32
- points.insert (pivot, 0 )
24
+ var points = sorted (deduplicate (gift), flipped_point_cmp)
25
+ let pivot = points[0 ]
26
+ sort (toOpenArray (points, 1 , high (points)),
27
+ proc (pa, pb: Point ): int =
28
+ if polar_angle (pivot, pa) < polar_angle (pivot, pb): - 1
29
+ else : 1 )
33
30
var
34
31
m = 1
35
32
en = toSeq (low (points) + 2 .. high (points))
You can’t perform that action at this time.
0 commit comments