summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Janlert <janlert@ardendo.se>2008-05-13 17:31:35 +1000
committerMagnus Janlert <janlert@ardendo.se>2008-05-13 17:31:35 +1000
commita223c6537f4f28e64b1f1277dc8f52631f29eaa7 (patch)
treedcd5a73533feda72711492dd91c09ada8af7881d
parent5cb808bded60d87b17394b72b36d689c0d0e29ae (diff)
downloadvigo-a223c6537f4f28e64b1f1277dc8f52631f29eaa7.tar.gz
vigo-a223c6537f4f28e64b1f1277dc8f52631f29eaa7.tar.bz2
prevent overflow
-rw-r--r--vigo.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/vigo.c b/vigo.c
index 0b0e3ad..5e80582 100644
--- a/vigo.c
+++ b/vigo.c
@@ -273,10 +273,10 @@ static VigoPoint
vigoCenterOfMass (Region r)
{
VigoPoint c;
- int m = 0;
+ float m = 0.0;
int j;
- c.x = 0;
- c.y = 0;
+ float x = 0.0;
+ float y = 0.0;
/* i should probably NOT be poking around in the Region-struct
* but.. i will anyway */
for (j = 0; j < r->numRects; j++)
@@ -284,13 +284,16 @@ vigoCenterOfMass (Region r)
BOX *b = &(r->rects[j]);
int w = (MAX (b->x1, b->x2) - MIN (b->x1, b->x2));
int h = (MAX (b->y1, b->y2) - MIN (b->y1, b->y2));
- int bm = w * h;
- c.x += bm * (b->x1 + b->x2) / 2;
- c.y += bm * (b->y1 + b->y2) / 2;
+ float bm = w * h;
+ x += bm * (b->x1 + b->x2) / 2;
+ y += bm * (b->y1 + b->y2) / 2;
+ printf(" iiiii %g * (%d + %d) / 2\n", bm, b->x1, b->x2);
+ printf("BOX %d,%d=%g\n", w, h, bm);
+ printf(" cx %g cy %g\n", x, y);
m += bm;
}
- c.x /= m;
- c.y /= m;
+ c.x = x / m;
+ c.y = y / m;
return c;
}