-
Notifications
You must be signed in to change notification settings - Fork 0
/
loc.c
43 lines (38 loc) · 753 Bytes
/
loc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "loc.h"
/* Builds a Loc with the x and y given */
Loc
make_loc (int x, int y)
{
Loc l;
l.x = x;
l.y = y;
return l;
}
/* Adds two Locs and returns the result */
Loc
add_locs (Loc left, Loc right)
{
left.x += right.x;
left.y += right.y;
return left;
}
/* Subtracts one loc from another */
Loc
subtract_locs (Loc left, Loc right)
{
left.x -= right.x;
left.y -= right.y;
return left;
}
/* Creates a new Loc by applying a delta to an existing one */
Loc
offset_loc (Loc origin, int dx, int dy)
{
return add_locs (origin, make_loc (dx, dy));
}
/* Decides if two locs are the same by comparing the fields. */
bool
equal_locs (Loc left, Loc right)
{
return left.x == right.x && left.y == right.y;
}