format: update .clang-format
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
#include "primitives.h"
|
||||
|
||||
VektorPolyline *vektor_polyline_new(void) {
|
||||
VektorPolyline *pl = malloc(sizeof(VektorPolyline));
|
||||
VektorPolyline* vektor_polyline_new(void) {
|
||||
VektorPolyline* pl = malloc(sizeof(VektorPolyline));
|
||||
pl->count = 0;
|
||||
pl->capacity = 4;
|
||||
pl->points = malloc(sizeof(V2) * pl->capacity);
|
||||
return pl;
|
||||
}
|
||||
|
||||
void vektor_polyline_add_point(VektorPolyline *pl, V2 point) {
|
||||
void vektor_polyline_add_point(VektorPolyline* pl, V2 point) {
|
||||
if (pl->count >= pl->capacity) {
|
||||
pl->capacity *= 2;
|
||||
pl->points = realloc(pl->points, sizeof(V2) * pl->capacity);
|
||||
@@ -16,22 +16,22 @@ void vektor_polyline_add_point(VektorPolyline *pl, V2 point) {
|
||||
pl->points[pl->count++] = point;
|
||||
}
|
||||
|
||||
void vektor_polyline_free(VektorPolyline *pl) {
|
||||
void vektor_polyline_free(VektorPolyline* pl) {
|
||||
if (!pl)
|
||||
return;
|
||||
free(pl->points);
|
||||
free(pl);
|
||||
}
|
||||
|
||||
VektorPolygon *vektor_polygon_new(void) {
|
||||
VektorPolygon *pg = malloc(sizeof(VektorPolygon));
|
||||
VektorPolygon* vektor_polygon_new(void) {
|
||||
VektorPolygon* pg = malloc(sizeof(VektorPolygon));
|
||||
pg->count = 0;
|
||||
pg->capacity = 4;
|
||||
pg->points = malloc(sizeof(V2) * pg->capacity);
|
||||
return pg;
|
||||
}
|
||||
|
||||
void vektor_polygon_add_point(VektorPolygon *pg, V2 point) {
|
||||
void vektor_polygon_add_point(VektorPolygon* pg, V2 point) {
|
||||
if (pg->count >= pg->capacity) {
|
||||
pg->capacity *= 2;
|
||||
pg->points = realloc(pg->points, sizeof(V2) * pg->capacity);
|
||||
@@ -39,14 +39,14 @@ void vektor_polygon_add_point(VektorPolygon *pg, V2 point) {
|
||||
pg->points[pg->count++] = point;
|
||||
}
|
||||
|
||||
void vektor_polygon_free(VektorPolygon *pg) {
|
||||
void vektor_polygon_free(VektorPolygon* pg) {
|
||||
if (!pg)
|
||||
return;
|
||||
free(pg->points);
|
||||
free(pg);
|
||||
}
|
||||
|
||||
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer *buffer,
|
||||
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer* buffer,
|
||||
VektorPrimitive prim) {
|
||||
if (buffer->count >= buffer->capacity) {
|
||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||
|
||||
@@ -11,13 +11,13 @@ typedef struct {
|
||||
} VektorLine;
|
||||
|
||||
typedef struct {
|
||||
V2 *points;
|
||||
V2* points;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} VektorPolyline;
|
||||
|
||||
typedef struct {
|
||||
V2 *points;
|
||||
V2* points;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} VektorPolygon;
|
||||
@@ -38,27 +38,27 @@ typedef struct {
|
||||
VektorPrimitiveKind kind;
|
||||
union {
|
||||
VektorLine line;
|
||||
VektorPolyline *polyline;
|
||||
VektorPolygon *polygon;
|
||||
VektorPolyline* polyline;
|
||||
VektorPolygon* polygon;
|
||||
VektorCircle circle;
|
||||
};
|
||||
} VektorPrimitive;
|
||||
|
||||
VektorPolyline *vektor_polyline_new(void);
|
||||
void vektor_polyline_add_point(VektorPolyline *pl, V2 point);
|
||||
void vektor_polyline_free(VektorPolyline *pl);
|
||||
VektorPolyline* vektor_polyline_new(void);
|
||||
void vektor_polyline_add_point(VektorPolyline* pl, V2 point);
|
||||
void vektor_polyline_free(VektorPolyline* pl);
|
||||
|
||||
VektorPolygon *vektor_polygon_new(void);
|
||||
void vektor_polygon_add_point(VektorPolygon *pl, V2 point);
|
||||
void vektor_polygon_free(VektorPolygon *pl);
|
||||
VektorPolygon* vektor_polygon_new(void);
|
||||
void vektor_polygon_add_point(VektorPolygon* pl, V2 point);
|
||||
void vektor_polygon_free(VektorPolygon* pl);
|
||||
|
||||
typedef struct {
|
||||
VektorPrimitive *primitives;
|
||||
VektorPrimitive* primitives;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} VektorPrimitiveBuffer;
|
||||
|
||||
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer *edges,
|
||||
void vektor_primitivebuffer_add_primitive(VektorPrimitiveBuffer* edges,
|
||||
VektorPrimitive edge);
|
||||
|
||||
#endif // PRIMITIVES_H_
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "stddef.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void vektor_edgebuffer_add_edge(EdgeBuffer *buffer, Edge edge) {
|
||||
void vektor_edgebuffer_add_edge(EdgeBuffer* buffer, Edge edge) {
|
||||
if (buffer->count >= buffer->capacity) {
|
||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||
buffer->edges = realloc(buffer->edges, sizeof(Edge) * buffer->capacity);
|
||||
@@ -11,18 +11,18 @@ void vektor_edgebuffer_add_edge(EdgeBuffer *buffer, Edge edge) {
|
||||
buffer->edges[buffer->count++] = edge;
|
||||
}
|
||||
|
||||
void vektor_line_flatten(EdgeBuffer *buffer, VektorLine line) {
|
||||
void vektor_line_flatten(EdgeBuffer* buffer, VektorLine line) {
|
||||
vektor_edgebuffer_add_edge(buffer, (Edge){line.p1, line.p2, 0});
|
||||
}
|
||||
|
||||
void vektor_polyline_flatten(EdgeBuffer *buffer, VektorPolyline *line) {
|
||||
void vektor_polyline_flatten(EdgeBuffer* buffer, VektorPolyline* line) {
|
||||
for (size_t i = 0; i + 1 < line->count; i++) {
|
||||
vektor_edgebuffer_add_edge(
|
||||
buffer, (Edge){line->points[i], line->points[i + 1], 0});
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_polygon_flatten(EdgeBuffer *buffer, VektorPolygon *pg) {
|
||||
void vektor_polygon_flatten(EdgeBuffer* buffer, VektorPolygon* pg) {
|
||||
size_t n = pg->count;
|
||||
if (n < 3)
|
||||
return;
|
||||
@@ -42,7 +42,7 @@ inline VektorFramebuffer vektor_framebuffer_new(unsigned int W,
|
||||
return fb;
|
||||
}
|
||||
|
||||
inline void vektor_framebuffer_putpixel(VektorFramebuffer *fb, int x, int y,
|
||||
inline void vektor_framebuffer_putpixel(VektorFramebuffer* fb, int x, int y,
|
||||
VektorColor color) {
|
||||
if ((unsigned)x >= fb->width || (unsigned)y >= fb->height)
|
||||
return;
|
||||
@@ -54,7 +54,7 @@ inline void vektor_framebuffer_putpixel(VektorFramebuffer *fb, int x, int y,
|
||||
fb->pixels[i + 3] = color.a;
|
||||
}
|
||||
|
||||
void draw_filled_circle(VektorFramebuffer *fb, int cx, int cy, int r,
|
||||
void draw_filled_circle(VektorFramebuffer* fb, int cx, int cy, int r,
|
||||
VektorColor color) {
|
||||
for (int y = -r; y <= r; y++) {
|
||||
int dx = (int)sqrt(r * r - y * y);
|
||||
@@ -64,7 +64,7 @@ void draw_filled_circle(VektorFramebuffer *fb, int cx, int cy, int r,
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_framebuffer_drawline(VektorFramebuffer *fb, V2 a, V2 b,
|
||||
void vektor_framebuffer_drawline(VektorFramebuffer* fb, V2 a, V2 b,
|
||||
VektorColor color, double thickness) {
|
||||
int x0 = (int)a.x;
|
||||
int y0 = (int)a.y;
|
||||
@@ -94,11 +94,11 @@ void vektor_framebuffer_drawline(VektorFramebuffer *fb, V2 a, V2 b,
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_framebuffer_rasterize(VektorFramebuffer *fb,
|
||||
VektorPrimitiveBuffer *prims) {
|
||||
void vektor_framebuffer_rasterize(VektorFramebuffer* fb,
|
||||
VektorPrimitiveBuffer* prims) {
|
||||
EdgeBuffer edges = {0};
|
||||
for (size_t i = 0; i < prims->count; i++) {
|
||||
VektorPrimitive *p = &prims->primitives[i];
|
||||
VektorPrimitive* p = &prims->primitives[i];
|
||||
|
||||
switch (p->kind) {
|
||||
case VEKTOR_LINE:
|
||||
|
||||
@@ -14,33 +14,33 @@ typedef struct {
|
||||
} Edge;
|
||||
|
||||
typedef struct {
|
||||
Edge *edges;
|
||||
Edge* edges;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} EdgeBuffer;
|
||||
|
||||
void vektor_edgebuffer_add_edge(EdgeBuffer *edges, Edge edge);
|
||||
void vektor_edgebuffer_add_edge(EdgeBuffer* edges, Edge edge);
|
||||
|
||||
void vektor_line_flatten(EdgeBuffer *edges, VektorLine line);
|
||||
void vektor_polyline_flatten(EdgeBuffer *edges, VektorPolyline *line);
|
||||
void vektor_polygon_flatten(EdgeBuffer *buffer, VektorPolygon *line);
|
||||
void vektor_line_flatten(EdgeBuffer* edges, VektorLine line);
|
||||
void vektor_polyline_flatten(EdgeBuffer* edges, VektorPolyline* line);
|
||||
void vektor_polygon_flatten(EdgeBuffer* buffer, VektorPolygon* line);
|
||||
|
||||
typedef struct {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned char *pixels; // Flat RGBA8 array
|
||||
unsigned char* pixels; // Flat RGBA8 array
|
||||
} VektorFramebuffer;
|
||||
|
||||
VektorFramebuffer vektor_framebuffer_new(unsigned int width,
|
||||
unsigned int height);
|
||||
|
||||
void vektor_framebuffer_putpixel(VektorFramebuffer *fb, int x, int y,
|
||||
void vektor_framebuffer_putpixel(VektorFramebuffer* fb, int x, int y,
|
||||
VektorColor color);
|
||||
|
||||
void vektor_framebuffer_drawline(VektorFramebuffer *fb, V2 a, V2 b,
|
||||
void vektor_framebuffer_drawline(VektorFramebuffer* fb, V2 a, V2 b,
|
||||
VektorColor color, double thickness);
|
||||
|
||||
void vektor_framebuffer_rasterize(VektorFramebuffer *fb,
|
||||
VektorPrimitiveBuffer *primitives);
|
||||
void vektor_framebuffer_rasterize(VektorFramebuffer* fb,
|
||||
VektorPrimitiveBuffer* primitives);
|
||||
|
||||
#endif // RASTER_H_
|
||||
|
||||
Reference in New Issue
Block a user