@@ -3,24 +3,24 @@ import numpy as np
3
3
4
4
5
5
data Point(x, y):
6
- def __add__(self, other is Point) = Point(self.x + other.x, self.y + other.y)
6
+ def __add__(self, Point(other) ) = Point(self.x + other.x, self.y + other.y)
7
7
8
8
9
9
# This function is necessary, because negative indices wrap around the
10
10
# array in Coconut.
11
- def inbounds(canvas_shape, location is Point) =
11
+ def inbounds(canvas_shape, Point(location) ) =
12
12
min(location) >= 0 and location.x < canvas_shape[0] and location.y < canvas_shape[1]
13
13
14
14
15
- def find_neighbours(canvas, location is Point, old_value):
15
+ def find_neighbours(canvas, Point(location) , old_value):
16
16
possible_neighbours = ((Point(0, 1), Point(1, 0), Point(0, -1), Point(-1, 0))
17
17
|> map$(location.__add__))
18
18
19
19
yield from possible_neighbours |> filter$(x -> (inbounds(canvas.shape, x)
20
20
and canvas[x] == old_value))
21
21
22
22
23
- def stack_fill(canvas, location is Point, old_value, new_value):
23
+ def stack_fill(canvas, Point(location) , old_value, new_value):
24
24
if new_value == old_value or not inbounds(canvas.shape, location):
25
25
return
26
26
@@ -33,7 +33,7 @@ def stack_fill(canvas, location is Point, old_value, new_value):
33
33
stack.extend(find_neighbours(canvas, current_location, old_value))
34
34
35
35
36
- def queue_fill(canvas, location is Point, old_value, new_value):
36
+ def queue_fill(canvas, Point(location) , old_value, new_value):
37
37
if new_value == old_value or not inbounds(canvas.shape, location):
38
38
return
39
39
@@ -49,7 +49,7 @@ def queue_fill(canvas, location is Point, old_value, new_value):
49
49
queue.append(neighbour)
50
50
51
51
52
- def recursive_fill(canvas, location is Point, old_value, new_value):
52
+ def recursive_fill(canvas, Point(location) , old_value, new_value):
53
53
if new_value == old_value or not inbounds(canvas.shape, location):
54
54
return
55
55
0 commit comments