Permalink
Browse files

update & apply new formatting rules

  • Loading branch information...
postspectacular committed Jul 21, 2016
1 parent 8ad6759 commit 108a6dcb94f1953c22c14a2709359f6a9a331818
Showing with 942 additions and 400 deletions.
  1. +9 −3 .clang-format
  2. +7 −5 examples/poisson/main.c
  3. +6 −5 examples/vatti/main.c
  4. +13 −6 src/data/adjacency.c
  5. +2 −1 src/data/adjacency.h
  6. +24 −11 src/data/cons.c
  7. +11 −4 src/data/cons.h
  8. +9 −3 src/data/consrc.c
  9. +34 −14 src/data/hashset.c
  10. +4 −1 src/data/hashset.h
  11. +65 −26 src/data/hashtable.c
  12. +18 −7 src/data/hashtable.h
  13. +29 −11 src/data/octree.c
  14. +8 −2 src/data/octree.h
  15. +26 −10 src/data/quadtree.c
  16. +7 −2 src/data/quadtree.h
  17. +32 −15 src/data/spatialgrid.c
  18. +24 −9 src/data/spatialgrid.h
  19. +2 −1 src/geom/circle.h
  20. +6 −3 src/geom/clip/liangbarsky.c
  21. +5 −2 src/geom/clip/liangbarsky.h
  22. +34 −21 src/geom/clip/vatti.c
  23. +15 −7 src/geom/clip/vatti.h
  24. +22 −10 src/geom/isec.c
  25. +19 −8 src/geom/isec.h
  26. +3 −1 src/geom/mesh.c
  27. +15 −6 src/geom/quadedge.c
  28. +6 −3 src/geom/triangle.c
  29. +18 −9 src/geom/triangle.h
  30. +45 −17 src/geom/voronoi.c
  31. +5 −2 src/geom/voronoi.h
  32. +17 −4 src/io/svg.c
  33. +17 −4 src/io/svg.h
  34. +3 −1 src/math/hashfn.c
  35. +7 −3 src/math/math.h
  36. +32 −14 src/math/matrix.c
  37. +24 −10 src/math/matrix.h
  38. +8 −3 src/math/poisson.c
  39. +10 −4 src/math/poisson.h
  40. +32 −12 src/math/vec.c
  41. +42 −21 src/math/vec2.h
  42. +9 −4 src/math/vec3.h
  43. +72 −36 src/math/vec3_common.h
  44. +9 −4 src/math/vec3_sse.h
  45. +9 −4 src/math/vec4.h
  46. +44 −22 src/math/vec4_common.h
  47. +9 −4 src/math/vec4_sse.h
  48. +14 −4 src/math/vec_arrayops.h
  49. +3 −1 src/mem/mpool.c
  50. +3 −1 src/mem/ref.h
  51. +6 −2 src/sim/ca.c
  52. +6 −2 src/sim/ca.h
  53. +24 −8 src/sim/verlet.c
  54. +16 −6 src/sim/verlet.h
  55. +3 −1 test/consrc.c
View
@@ -1,6 +1,12 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: None
AllowAllParametersOfDeclarationOnNextLine: false
AlignConsecutiveAssignments: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackParameters: false
BreakBeforeBraces: Attach
ColumnLimit: 80
ReflowComments: false
SortIncludes: true
AlignConsecutiveAssignments: true
SortIncludes: true
View
@@ -49,11 +49,13 @@ static AppState state = {
static float disc_gen(CT_Quadtree *t, CT_Circle2f *disc, void *s) {
ct_set2fxy(&disc->pos, ct_rand_normpos() * t->root.w,
ct_rand_normpos() * t->root.h);
size_t x = (size_t)disc->pos.x;
size_t y = (size_t)disc->pos.y;
AppState *state = (AppState *)s;
float tt = (float)state->image[y * state->width + x] / 255.f;
if (state->invert) tt = 1.0f - tt;
size_t x = (size_t)disc->pos.x;
size_t y = (size_t)disc->pos.y;
AppState *state = (AppState *)s;
float tt = (float)state->image[y * state->width + x] / 255.f;
if (state->invert) {
tt = 1.0f - tt;
}
return disc->r =
ct_mixf(state->minDist, state->maxDist, powf(tt, state->gamma));
}
View
@@ -23,14 +23,15 @@ int main() {
{590, 100}, {350, 300}, {200, 200}};
//CT_Vec2f a[] = {{100, 100}, {300, 200}, {400, 100}, {500, 300}, {50, 300}};
//CT_Vec2f b[] = {{10, 10}, {590, 100}, {590, 130}, {10, 250}};
FILE *out = fopen("assets/vatti.svg", "w");
FILE *out = fopen("assets/vatti.svg", "w");
ct_svg_start_doc(
out, ct_svg_attribs(0, 3, SVG_INT("width", 600), SVG_INT("height", 600),
SVG_STR("fill", "none")));
fprintf(out,
"<defs><pattern id=\"P1\" width=\"10\" height=\"10\" "
"patternUnits=\"userSpaceOnUse\"><path d=\"M0,0 L10,10\" "
"stroke=\"#00f\"/></pattern></defs>");
fputs(
"<defs><pattern id=\"P1\" width=\"10\" height=\"10\" "
"patternUnits=\"userSpaceOnUse\"><path d=\"M0,0 L10,10\" "
"stroke=\"#00f\"/></pattern></defs>",
out);
CT_ClipContext ctx;
ct_clip_init_context(&ctx, 32);
for (size_t i = 0; i < 4; i++) {
View
@@ -4,7 +4,8 @@
#include "data/adjacency.h"
#include "math/math.h"
ct_inline size_t cell_index(const CT_AdjMatrix *mat, const size_t x,
ct_inline size_t cell_index(const CT_AdjMatrix *mat,
const size_t x,
const size_t y) {
return x * mat->stride + (y >> 3);
}
@@ -21,7 +22,8 @@ ct_export void ct_adjmat_free(CT_AdjMatrix *mat) {
free(mat->bits);
}
ct_export int ct_adjmat_join(CT_AdjMatrix *mat, const size_t x,
ct_export int ct_adjmat_join(CT_AdjMatrix *mat,
const size_t x,
const size_t y) {
CT_CHECK(x < mat->stride << 3, "x out of bounds");
CT_CHECK(y < mat->stride << 3, "y out of bounds");
@@ -36,7 +38,8 @@ ct_export int ct_adjmat_join(CT_AdjMatrix *mat, const size_t x,
return 1;
}
ct_export int ct_adjmat_disjoin(CT_AdjMatrix *mat, const size_t x,
ct_export int ct_adjmat_disjoin(CT_AdjMatrix *mat,
const size_t x,
const size_t y) {
CT_CHECK(x < mat->stride << 3, "x out of bounds");
CT_CHECK(y < mat->stride << 3, "y out of bounds");
@@ -51,7 +54,8 @@ ct_export int ct_adjmat_disjoin(CT_AdjMatrix *mat, const size_t x,
return 1;
}
ct_export int ct_adjmat_is_join(CT_AdjMatrix *mat, const size_t x,
ct_export int ct_adjmat_is_join(CT_AdjMatrix *mat,
const size_t x,
const size_t y) {
CT_CHECK(x < mat->stride << 3, "x out of bounds");
CT_CHECK(y < mat->stride << 3, "y out of bounds");
@@ -78,7 +82,8 @@ ct_export void ct_adjmat_trace(const CT_AdjMatrix *mat) {
}
}
ct_export int ct_adjmat_iterate(const CT_AdjMatrix *mat, CT_AdjMatIterator iter,
ct_export int ct_adjmat_iterate(const CT_AdjMatrix *mat,
CT_AdjMatIterator iter,
void *state) {
uint8_t *ptr = mat->bits;
for (size_t y = 0, w = mat->stride << 3; y < w; y++) {
@@ -90,7 +95,9 @@ ct_export int ct_adjmat_iterate(const CT_AdjMatrix *mat, CT_AdjMatIterator iter,
b++, bv <<= 1, xx++) {
if (cell & bv) {
int res = iter(xx, y, state);
if (res) return res;
if (res) {
return res;
}
}
}
}
View
@@ -21,7 +21,8 @@ int ct_adjmat_join(CT_AdjMatrix *mat, size_t x, size_t y);
int ct_adjmat_disjoin(CT_AdjMatrix *mat, size_t x, size_t y);
int ct_adjmat_is_join(CT_AdjMatrix *mat, size_t x, size_t y);
void ct_adjmat_trace(const CT_AdjMatrix *mat);
int ct_adjmat_iterate(const CT_AdjMatrix *mat, CT_AdjMatIterator iter,
int ct_adjmat_iterate(const CT_AdjMatrix *mat,
CT_AdjMatIterator iter,
void *state);
CT_END_DECLS
View
@@ -49,7 +49,8 @@ ct_export void ct_cons_free_all(CT_Cons* cell, size_t freeVal) {
}
}
ct_export void* ct_cons_iterate(CT_Cons* cell, CT_ConsVisitor visit,
ct_export void* ct_cons_iterate(CT_Cons* cell,
CT_ConsVisitor visit,
void* state) {
while (cell != NULL) {
visit(cell, state);
@@ -58,8 +59,10 @@ ct_export void* ct_cons_iterate(CT_Cons* cell, CT_ConsVisitor visit,
return state;
}
ct_export void* ct_cons_iterate_n(CT_Cons* cell, CT_ConsVisitor visit,
void* state, size_t num) {
ct_export void* ct_cons_iterate_n(CT_Cons* cell,
CT_ConsVisitor visit,
void* state,
size_t num) {
while (cell != NULL && num--) {
visit(cell, state);
cell = cell->next;
@@ -69,14 +72,19 @@ ct_export void* ct_cons_iterate_n(CT_Cons* cell, CT_ConsVisitor visit,
ct_export CT_Cons* ct_cons_find(CT_Cons* cell, void* value) {
while (cell != NULL) {
if (cell->value == value) return cell;
if (cell->value == value) {
return cell;
}
cell = cell->next;
}
return NULL;
}
ct_export CT_Cons* ct_cons_from_array(void* values, size_t num, size_t stride,
CT_Cons* head, CT_MPool* mpool) {
ct_export CT_Cons* ct_cons_from_array(void* values,
size_t num,
size_t stride,
CT_Cons* head,
CT_MPool* mpool) {
if (num > 0) {
values += (num - 1) * stride;
while (num--) {
@@ -87,7 +95,9 @@ ct_export CT_Cons* ct_cons_from_array(void* values, size_t num, size_t stride,
return head;
}
ct_export CT_Cons* ct_cons_from_parray(void** values, size_t num, CT_Cons* head,
ct_export CT_Cons* ct_cons_from_parray(void** values,
size_t num,
CT_Cons* head,
CT_MPool* mpool) {
if (num > 0) {
values += num - 1;
@@ -114,7 +124,8 @@ ct_export CT_Cons* ct_cons_concat_imm(CT_Cons* head, CT_Cons* rest) {
return head;
}
ct_export CT_Cons* ct_cons_concat(CT_Cons* head, CT_Cons* rest,
ct_export CT_Cons* ct_cons_concat(CT_Cons* head,
CT_Cons* rest,
CT_MPool* mpool) {
CT_ConsCloneState state = {.head = NULL, .pool = mpool};
ct_cons_iterate(head, ct_cons_iterate_clone,
@@ -133,9 +144,11 @@ ct_export CT_Cons* ct_cons_take(CT_Cons* head, size_t num, CT_MPool* mpool) {
ct_export CT_ConsD* ct_consd(void* x, CT_ConsD* head, CT_MPool* mpool) {
CT_ConsD* cell = CT_MP_ALLOC(mpool, CT_ConsD);
CT_CHECK_MEM(cell);
cell->value = x;
cell->next = head;
if (head) head->prev = cell;
cell->value = x;
cell->next = head;
if (head) {
head->prev = cell;
}
fail:
return cell;
}
View
@@ -25,11 +25,18 @@ CT_Cons* ct_cons(void* x, CT_Cons* head, CT_MPool* mpool);
void ct_cons_free(CT_Cons* cell, size_t freeVal);
void ct_cons_free_all(CT_Cons* cell, size_t freeVal);
void* ct_cons_iterate(CT_Cons* cell, CT_ConsVisitor visit, void* state);
void* ct_cons_iterate_n(CT_Cons* cell, CT_ConsVisitor visit, void* state,
void* ct_cons_iterate_n(CT_Cons* cell,
CT_ConsVisitor visit,
void* state,
size_t num);
CT_Cons* ct_cons_from_array(void* values, size_t num, size_t stride,
CT_Cons* head, CT_MPool* mpool);
CT_Cons* ct_cons_from_parray(void** values, size_t num, CT_Cons* head,
CT_Cons* ct_cons_from_array(void* values,
size_t num,
size_t stride,
CT_Cons* head,
CT_MPool* mpool);
CT_Cons* ct_cons_from_parray(void** values,
size_t num,
CT_Cons* head,
CT_MPool* mpool);
CT_Cons* ct_cons_concat_imm(CT_Cons* head, CT_Cons* rest);
CT_Cons* ct_cons_concat(CT_Cons* head, CT_Cons* rest, CT_MPool* mpool);
View
@@ -55,8 +55,12 @@ static void ct_consrc_free(const CT_Ref *ref) {
CT_ConsRC *c = ct_object_cons_ptr(o);
CT_Object *next = c->next;
CT_DEBUG("free cons: %p->%p val: %p", o, next, c->value);
if (c->value) ct_ref_dec(&c->value->rc);
if (next) ct_ref_dec(&next->rc);
if (c->value) {
ct_ref_dec(&c->value->rc);
}
if (next) {
ct_ref_dec(&next->rc);
}
ct_mpool_free_block(&__ct_consrc.pool, c);
ct_object_free_box(o);
}
@@ -89,7 +93,9 @@ CT_Object *ct_consrc_pop_imm(CT_Object **list) {
CT_CHECK(ct_object_is(*list, CT_TYPE_CONS), "%p is not a cons", *list);
CT_Object *node = *list;
*list = ct_object_cons_ptr(node)->next;
if (*list) ct_ref_inc(&(*list)->rc);
if (*list) {
ct_ref_inc(&(*list)->rc);
}
return node;
fail:
return NULL;
View
@@ -5,7 +5,9 @@
#include "data/hashset.h"
#include "math/math.h"
static int make_key(const CT_Hashset* s, CT_HSEntry* e, const void* key,
static int make_key(const CT_Hashset* s,
CT_HSEntry* e,
const void* key,
const uint32_t ks) {
if (s->flags & CT_HS_CONST_KEYS) {
e->key = (void*)key;
@@ -15,14 +17,17 @@ static int make_key(const CT_Hashset* s, CT_HSEntry* e, const void* key,
} else {
e->key = malloc(ks);
}
if (!e->key) return 1;
if (!e->key) {
return 1;
}
memcpy(e->key, key, ks);
}
e->keySize = ks;
return 0;
}
static CT_HSEntry* make_entry(CT_Hashset* s, const void* key,
static CT_HSEntry* make_entry(CT_Hashset* s,
const void* key,
const uint32_t ks) {
CT_HSEntry* e = ct_mpool_alloc(&s->pool);
CT_CHECK_MEM(e);
@@ -52,13 +57,17 @@ static void free_entry(CT_Hashset* s, const CT_HSEntry* e) {
ct_mpool_free_block(&s->pool, e);
}
static int equiv_keys(const void* a, const void* b, const uint32_t sa,
static int equiv_keys(const void* a,
const void* b,
const uint32_t sa,
const uint32_t sb) {
return sa == sb ? !memcmp(a, b, sa) : 0;
}
static CT_HSEntry* find_entry(const CT_Hashset* s, CT_HSEntry* e,
const void* key, const uint32_t ks) {
static CT_HSEntry* find_entry(const CT_Hashset* s,
CT_HSEntry* e,
const void* key,
const uint32_t ks) {
int (*equiv_keys)(const void*, const void*, uint32_t, uint32_t) =
s->ops.equiv_keys;
while (e != NULL) {
@@ -71,7 +80,9 @@ static CT_HSEntry* find_entry(const CT_Hashset* s, CT_HSEntry* e,
return e;
}
static int cons_entry(CT_Hashset* s, const uint32_t bin, const void* key,
static int cons_entry(CT_Hashset* s,
const uint32_t bin,
const void* key,
const uint32_t ks) {
// TODO resize?
CT_HSEntry* e = make_entry(s, key, ks);
@@ -82,7 +93,8 @@ static int cons_entry(CT_Hashset* s, const uint32_t bin, const void* key,
return e == NULL;
}
static void delete_entry(CT_Hashset* s, const uint32_t bin,
static void delete_entry(CT_Hashset* s,
const uint32_t bin,
const CT_HSEntry* e) {
CT_HSEntry* first = s->bins[bin];
CT_HSEntry* rest = first->next;
@@ -106,8 +118,11 @@ static void delete_entry(CT_Hashset* s, const uint32_t bin,
}
}
ct_export int ct_hs_init(CT_Hashset* s, const CT_HSOps* ops, size_t num,
const size_t poolSize, const CT_HSFlags flags) {
ct_export int ct_hs_init(CT_Hashset* s,
const CT_HSOps* ops,
size_t num,
const size_t poolSize,
const CT_HSFlags flags) {
int mp = ct_mpool_init(&s->pool, poolSize, sizeof(CT_HSEntry));
if (!mp) {
num = ct_ceil_pow2(num);
@@ -168,7 +183,8 @@ ct_export int ct_hs_assoc(CT_Hashset* s, const void* key, const uint32_t ks) {
return 1;
}
ct_export void* ct_hs_get(const CT_Hashset* s, const void* key,
ct_export void* ct_hs_get(const CT_Hashset* s,
const void* key,
const uint32_t ks) {
uint32_t bin = s->ops.hash(key, ks) & s->binMask;
CT_HSEntry* e = s->bins[bin];
@@ -178,7 +194,8 @@ ct_export void* ct_hs_get(const CT_Hashset* s, const void* key,
return (e ? e->key : NULL);
}
ct_export int ct_hs_contains(const CT_Hashset* s, const void* key,
ct_export int ct_hs_contains(const CT_Hashset* s,
const void* key,
const uint32_t ks) {
return (ct_hs_get(s, key, ks) != NULL);
}
@@ -197,13 +214,16 @@ ct_export int ct_hs_dissoc(CT_Hashset* s, const void* key, const uint32_t ks) {
return 1;
}
ct_export int ct_hs_iterate(const CT_Hashset* s, CT_HSIterator iter,
ct_export int ct_hs_iterate(const CT_Hashset* s,
CT_HSIterator iter,
void* state) {
for (size_t i = 0; i <= s->binMask; i++) {
CT_HSEntry* e = s->bins[i];
while (e != NULL) {
int res = iter(e, state);
if (res) return res;
if (res) {
return res;
}
e = e->next;
}
}
View
@@ -44,7 +44,10 @@ typedef struct CT_Hashset {
uint32_t collisions;
} CT_Hashset;
int ct_hs_init(CT_Hashset* s, const CT_HSOps* ops, size_t num, size_t poolSize,
int ct_hs_init(CT_Hashset* s,
const CT_HSOps* ops,
size_t num,
size_t poolSize,
CT_HSFlags flags);
void ct_hs_free(CT_Hashset* s);
void* ct_hs_get(const CT_Hashset* s, const void* key, uint32_t ks);
Oops, something went wrong.

0 comments on commit 108a6dc

Please sign in to comment.