Skip to content

Commit aa5a5b6

Browse files
committed
Add mushbounds_size helper
1 parent fab2c9c commit aa5a5b6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

bounds.all.c

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
#include <assert.h>
66

7+
size_t mushbounds_size(const mushbounds* bounds) {
8+
size_t sz = 1;
9+
for (mushdim i = 0; i < MUSHSPACE_DIM; ++i)
10+
sz *= bounds->end.v[i] - bounds->beg.v[i] + 1;
11+
return sz;
12+
}
713
size_t mushbounds_clamped_size(const mushbounds* bounds) {
814
size_t sz = mush_size_t_add_clamped(bounds->end.v[0] - bounds->beg.v[0], 1);
915
for (mushdim i = 1; i < MUSHSPACE_DIM; ++i)

bounds.all.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct mushbounds {
1515

1616
MUSH_DECL_CONST_DYN_ARRAY(mushbounds)
1717

18+
#define mushbounds_size MUSHSPACE_CAT(mushbounds,_size)
1819
#define mushbounds_clamped_size MUSHSPACE_CAT(mushbounds,_clamped_size)
1920
#define mushbounds_contains MUSHSPACE_CAT(mushbounds,_contains)
2021
#define mushbounds_safe_contains MUSHSPACE_CAT(mushbounds,_safe_contains)
@@ -28,6 +29,7 @@ MUSH_DECL_CONST_DYN_ARRAY(mushbounds)
2829
#define mushbounds_can_fuse MUSHSPACE_CAT(mushbounds,_can_fuse)
2930
#define mushbounds_tessellate MUSHSPACE_CAT(mushbounds,_tessellate)
3031

32+
size_t mushbounds_size (const mushbounds*);
3133
size_t mushbounds_clamped_size(const mushbounds*);
3234

3335
// The safe versions work even if the bounds have beg > end.

0 commit comments

Comments
 (0)