#include #include #include #include #include "util.h" #include "array.h" #include "face.h" struct face *read_face(const char *name) { FILE *file; struct face *f; float x, y, z; int xi, yi, zi; file = strcmp(name, "-") ? fopen(name, "r") : stdin; if (!file) { perror(name); exit(1); } f = alloc_type(struct face); f->a = new_array(); while (fscanf(file, "%f,%f,%f\r\n", &x, &y, &z) == 3) { /* @@@ hack - should auto-scale */ xi = round(x*10.0); yi = round(y*10.0); zi = round(z*40.0); set(f->a, xi, yi, zi); } (void) fclose(file); f->sx = f->a->max_x-f->a->min_x+1; f->sy = f->a->max_y-f->a->min_y+1; f->z_ref = (f->a->min_z+f->a->max_z)/2; fprintf(stderr, "%d-%d / %d-%d / %d-%d\n", f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y, f->a->min_z, f->a->max_z); return f; }