Skip to content

Commit 679b302

Browse files
committed
Merge branch 'main' into bezier
2 parents e443513 + ea107c6 commit 679b302

File tree

11 files changed

+284
-141
lines changed

11 files changed

+284
-141
lines changed

display/rendering/canvas.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
#include <sys/mman.h>
1212
#include <unistd.h>
1313

14-
#define DEFN_RENDER(type, body) \
15-
void rendering_draw_##type(struct canvas *c, const struct type *type) \
16-
{ \
17-
body \
18-
} \
19-
\
20-
void rendering_draw_##type##_type_erased( \
21-
struct canvas *c, const void *v) \
22-
{ \
23-
rendering_draw_##type(c, v); \
24-
}
14+
// The function body goes after macro invocation.
15+
#define DEFN_RENDER(type) \
16+
void rendering_draw_##type##_type_erased( \
17+
struct canvas *c, const void *v) \
18+
{ \
19+
rendering_draw_##type(c, v); \
20+
} \
21+
void rendering_draw_##type(struct canvas *c, const struct type *type)
2522

2623
static inline intmax_t min(intmax_t, intmax_t);
2724
static inline intmax_t max(intmax_t, intmax_t);
@@ -68,15 +65,15 @@ void rendering_fill(struct canvas *c, struct color color)
6865
draw_point(c, x, y, color);
6966
}
7067

71-
DEFN_RENDER(rect, {
68+
DEFN_RENDER(rect) {
7269
uint16_t right_edge = rect->x + rect->w;
7370
uint16_t bottom_edge = rect->y + rect->h;
7471
for (uint16_t y = rect->y; y < bottom_edge && y < c->height; y++)
7572
for (uint16_t x = rect->x; x < right_edge && x < c->width; x++)
7673
draw_point(c, x, y, rect->c);
77-
})
74+
}
7875

79-
DEFN_RENDER(circle, {
76+
DEFN_RENDER(circle) {
8077
uint16_t x = circle->r;
8178
uint16_t y = 0;
8279
int32_t t1 = circle->r / 16;
@@ -124,9 +121,9 @@ DEFN_RENDER(circle, {
124121
x--;
125122
}
126123
}
127-
})
124+
}
128125

129-
DEFN_RENDER(line, {
126+
DEFN_RENDER(line) {
130127
const struct color color = line->c;
131128

132129
// I think this is essentially Bresenham's line algorithm, as in, that
@@ -211,9 +208,9 @@ DEFN_RENDER(line, {
211208
d1_y -= steps * lstep_y;
212209
}
213210
}
214-
})
211+
}
215212

216-
DEFN_RENDER(rect_copy, {
213+
DEFN_RENDER(rect_copy) {
217214
const struct rect_copy rc = *rect_copy;
218215

219216
// The regions may overlap, so we care whether we are incrementing or
@@ -250,7 +247,7 @@ DEFN_RENDER(rect_copy, {
250247
memmove(&c->buffer[dst_idx], &c->buffer[src_idx],
251248
(size_t)safe_width * 4);
252249
}
253-
})
250+
}
254251

255252
static void bezier2_compute(struct bezier2 b, float t, float *x, float *y)
256253
{
@@ -275,7 +272,7 @@ static float bezier2_arclen_approx(struct bezier2 b, size_t n)
275272
return dist;
276273
}
277274

278-
DEFN_RENDER(bezier2, {
275+
DEFN_RENDER(bezier2) {
279276
const struct bezier2 b = *bezier2;
280277

281278
// TODO: not pixel perfect (this approach is heuristic)
@@ -294,7 +291,7 @@ DEFN_RENDER(bezier2, {
294291
bezier2_compute(b, t, &px, &py);
295292
draw_point(c, roundf(px), roundf(py), b.c);
296293
}
297-
})
294+
}
298295

299296
void rendering_dump_bgra_to_rgba(
300297
const struct canvas *c, DIR *dir, const char *dirpath, const char *path)

0 commit comments

Comments
 (0)