Skip to content

Commit 7f29f64

Browse files
committed
proc -> func
1 parent f9b6a87 commit 7f29f64

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

contents/graham_scan/code/nim/graham.nim

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ import sugar
55

66
type Point[T: SomeNumber] = tuple[x, y: T]
77

8-
proc tup_to_point[T](t: (T, T)): Point[T] =
8+
func tup_to_point[T](t: (T, T)): Point[T] =
99
(x: t[0], y: t[1])
1010

11-
proc cross_product[T](p1, p2, p3: Point[T]): T =
11+
func cross_product[T](p1, p2, p3: Point[T]): T =
1212
## Form the cross product of three points. If the result is
1313
## - zero, the points are collinear.
1414
## - positive, the points form a counter-clockwise "left" turn.
1515
## - negative, the points form a clockwise "right" turn.
1616
(p3.y - p1.y) * (p2.x - p1.x) - (p2.y - p1.y) * (p3.x - p1.x)
1717

18-
proc polar_angle(reference, point: Point): float =
18+
func polar_angle(reference, point: Point): float =
1919
## Find the polar angle of a point relative to a reference point
2020
arctan2(float(point.y - reference.y), float(point.x - reference.x))
2121

22-
proc flipped_point_cmp(pa, pb: Point): int =
22+
func flipped_point_cmp(pa, pb: Point): int =
2323
## Compare points first by their y-coordinate, then x-coordinate.
2424
if (pa.y, pa.x) < (pb.y, pb.x): -1
2525
elif pa == pb: 0
2626
else: 1
2727

28-
proc graham_scan(gift: seq[Point]): seq[Point] =
28+
func graham_scan(gift: seq[Point]): seq[Point] =
2929
assert(gift.len >= 3)
3030
var points = sorted(deduplicate(gift), flipped_point_cmp)
3131
let pivot = points[0]
3232
# Mimic sorting a sliced sequence without copying
3333
sort(toOpenArray(points, 1, high(points)),
34-
proc (pa, pb: Point): int =
34+
func (pa, pb: Point): int =
3535
if polar_angle(pivot, pa) < polar_angle(pivot, pb): -1
3636
else: 1)
3737
var

0 commit comments

Comments
 (0)