summaryrefslogtreecommitdiff
path: root/meme/plane.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-13 00:15:06 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-13 00:15:06 (GMT)
commit78fa384e07179f49fabe8a39b54c0b061bce8666 (patch)
treef1403cf40907ffd5fc25216b08d3087129f355cd /meme/plane.c
parent2cff1edad1a3ff6e4379ec90602c276a1a27dd51 (diff)
downloadmisc-78fa384e07179f49fabe8a39b54c0b061bce8666.zip
misc-78fa384e07179f49fabe8a39b54c0b061bce8666.tar.gz
misc-78fa384e07179f49fabe8a39b54c0b061bce8666.tar.bz2
meme/plane.c: use correct element size for point array; correct interpolation
Diffstat (limited to 'meme/plane.c')
-rw-r--r--meme/plane.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/meme/plane.c b/meme/plane.c
index 1a9b7ce..a2a392c 100644
--- a/meme/plane.c
+++ b/meme/plane.c
@@ -33,12 +33,11 @@ static void add_point(struct cut *cut, int x, int y)
struct point *p;
if (!cut->res)
- cut->res = calloc(ALLOC, sizeof(struct point *));
+ cut->res = calloc(ALLOC, sizeof(struct point));
/* this tests if we're at a 2^n boundary */
if (cut->n >= ALLOC && (cut->n & (cut->n - 1)) == 0)
- cut->res = realloc(cut->res,
- cut->n * 2 * sizeof(struct point *));
+ cut->res = realloc(cut->res, cut->n * 2 * sizeof(struct point));
p = &cut->res[cut->n];
p->x = x;
p->y = y;
@@ -51,7 +50,7 @@ static bool cut_xz(const struct vertex *a, const struct vertex *b, void *user)
struct cut *cut = user;
int y = cut->coord;
int dx, dy, dz;
- float fx, fz;;
+ float f;;
if ((a->y > y || b->y < y) && (a->y < y || b->y > y))
return 0;
@@ -64,9 +63,8 @@ static bool cut_xz(const struct vertex *a, const struct vertex *b, void *user)
dx = a->x - b->x;
dy = a->y - b->y;
dz = a->z - b->z;
- fx = dx/(float) dy;
- fz = dz/(float) dy;
- add_point(cut, b->x + fx * dx, b->z + fz * dz);
+ f = (y - b->y)/(float) dy;
+ add_point(cut, b->x + f * dx, b->z + f * dz);
return 0;
}
@@ -94,7 +92,7 @@ struct point *plane_xz(int y, unsigned *n)
};
edge_foreach(cut_xz, &cut);
- qsort(cut.res, cut.n, sizeof(struct point *), comp_x);
+ qsort(cut.res, cut.n, sizeof(struct point), comp_x);
*n = cut.n-1;
return cut.res;
}