-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoords.all.c
59 lines (52 loc) · 1.6 KB
/
coords.all.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// File created: 2011-08-07 18:20:32
#include "coords.all.h"
void mushcoords_max_into(mushcoords* a, mushcoords b) {
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i)
a->v[i] = mushcell_max(a->v[i], b.v[i]);
}
void mushcoords_min_into(mushcoords* a, mushcoords b) {
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i)
a->v[i] = mushcell_min(a->v[i], b.v[i]);
}
#define DEFINE_OP(NAME) \
mushcoords mushcoords_##NAME(mushcoords a, mushcoords b) { \
mushcoords x = a; \
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i) \
x.v[i] = mushcell_##NAME(x.v[i], b.v[i]); \
return x; \
} \
void mushcoords_##NAME##_into(mushcoords* a, mushcoords b) { \
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i) \
a->v[i] = mushcell_##NAME(a->v[i], b.v[i]); \
} \
mushcoords mushcoords_##NAME##s(mushcoords a, mushcell b) { \
mushcoords x = a; \
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i) \
x.v[i] = mushcell_##NAME(x.v[i], b); \
return x; \
}
DEFINE_OP(add)
DEFINE_OP(sub)
DEFINE_OP(mul)
#if !MUSHSPACE_93
#define DEFINE_CLAMPED_OP(NAME) \
mushcoords mushcoords_##NAME##s_clamped(mushcoords a, mushcell b) { \
mushcoords x = a; \
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i) \
x.v[i] = mushcell_##NAME##_clamped(x.v[i], b); \
return x; \
}
DEFINE_CLAMPED_OP(add)
DEFINE_CLAMPED_OP(sub)
#endif
bool mushcoords_equal(mushcoords a, mushcoords b) {
// Yes, peeling the loop is worth it.
return a.v[0] == b.v[0]
#if MUSHSPACE_DIM >= 2
&& a.v[1] == b.v[1]
#if MUSHSPACE_DIM >= 3
&& a.v[2] == b.v[2]
#endif
#endif
;
}