X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffrac.c;h=071b5c23542fb8a7e1695b210bc0f25517c6ca62;hb=34e07fdc87e289e9ce574df7755e5e781136c20b;hp=8a6bcae807ba0407234fc5f2c1b8e1b5f87b9b1a;hpb=7e22a9e6549bf0ff36dc9a73c243de1f4b36b4a4;p=meshfrac diff --git a/src/frac.c b/src/frac.c index 8a6bcae..071b5c2 100644 --- a/src/frac.c +++ b/src/frac.c @@ -4,6 +4,7 @@ #include "dynarr.h" static void destroy_cell(struct frac_cell *cell); +static int build_cell(struct fracture *frac, int cellidx); int frac_init(struct fracture *frac) { @@ -70,6 +71,8 @@ int frac_num_cells(struct fracture *frac) return dynarr_size(frac->cells); } +/* --- step 1: generate a bunch of points (or let the user add them manually) */ + int frac_gen_points(struct fracture *frac, int num) { int i; @@ -97,11 +100,49 @@ int frac_gen_points(struct fracture *frac, int num) return 0; } + +/* --- step 2: construct voronoi cells bounded by planes */ + int frac_build_cells(struct fracture *frac) { + int i; + + for(i=0; icells); i++) { + if(build_cell(frac, i) == -1) { + return -1; + } + } + return -1; } +static int build_cell(struct fracture *frac, int cellidx) +{ + int i, j, num; + struct plane plane, *pptr; + struct frac_cell *cell = frac->cells + cellidx; + + num = dynarr_size(frac->cells); + for(i=0; ipt, &frac->cells[i].pt); + if(!(pptr = dynarr_push(cell->planes, &plane))) { + return -1; + } + cell->planes = pptr; + } + + /* clip all planes against each other to end up with a convex cell */ + num = dynarr_size(cell->planes); + for(i=0; i