diff --git a/solidify/face.h b/solidify/face.h index 4d37086..ab6c5cf 100644 --- a/solidify/face.h +++ b/solidify/face.h @@ -13,6 +13,8 @@ #ifndef FACE_H #define FACE_H +#include + #include "array.h" #include "matrix.h" @@ -34,6 +36,30 @@ static inline double face_z0(const struct face *f, int x, int y) } +static inline double fx_to_angle(const struct face *f) +{ + return atan(f->fx)/M_PI*180; +} + + +static inline double fy_to_angle(const struct face *f) +{ + return atan(f->fy)/M_PI*180; +} + + +static inline void fx_from_angle(struct face *f, double a) +{ + f->fx = tan(a/180*M_PI); +} + + +static inline void fy_from_angle(struct face *f, double a) +{ + f->fy = tan(a/180*M_PI); +} + + struct face *read_face(const char *name); #endif /* !FACE_H */ diff --git a/solidify/povray.c b/solidify/povray.c index b5bcf45..60b8a3c 100644 --- a/solidify/povray.c +++ b/solidify/povray.c @@ -109,7 +109,7 @@ static void povray_face(FILE *file, const struct face *f, const char *side, "\t}\n", prefix, side, f->sx*f->x_step, (f->sz-1)*f->z_step, f->sy*f->y_step, -f->sx*f->x_step/2, f->sy*f->y_step/2, - -atan(f->fy)/M_PI*180, atan(f->fx)/M_PI*180, + -fy_to_angle(f), fx_to_angle(f), f->a->min_z*f->z_step, -f->z_ref*f->z_step, a, diff --git a/solidify/project.c b/solidify/project.c index 28a4582..a0991a6 100644 --- a/solidify/project.c +++ b/solidify/project.c @@ -72,11 +72,11 @@ static void read_face_data(FILE *file, struct face *f) if (fscanf(file, "%f", &v) != 1) return; - f->fx = -tan(v/180*M_PI); + fx_from_angle(f, v); if (fscanf(file, "%f", &v) != 1) return; - f->fy = tan(v/180*M_PI); + fy_from_angle(f, v); if (fscanf(file, "%f", &v) != 1) return; @@ -163,7 +163,7 @@ static void save_face_data(FILE *file, const char *name, const struct face *f) a = 180-a; if (fprintf(file, "%g %g %g\n%g %g %g\n", f->z_ref*f->z_step, - -atan(f->fx)/M_PI*180, atan(f->fy)/M_PI*180, + fx_to_angle(f), fy_to_angle(f), a, f->m.b[0]*f->x_step, f->m.b[1]*f->y_step) < 0) { perror(name); exit(1);