Index: trunk/magic/remove/src/warpedpixels.c
===================================================================
--- trunk/magic/remove/src/warpedpixels.c	(revision 20664)
+++ trunk/magic/remove/src/warpedpixels.c	(revision 20665)
@@ -33,5 +33,5 @@
     }
 
-    bool writeTouchedPixels = false;
+    bool writeTouchedPixels = false; // XXX: make this an argument to the program
     if (writeTouchedPixels) {
         // write out the warped pixels
@@ -123,9 +123,9 @@
     // Now set the touched pixels
     int ymin = fmax(0, pt[1].y);
-    int ymax = fmin(pt[3].y, sf->warpedPixels->numRows);
+    int ymax = fmin(pt[3].y + .5, sf->warpedPixels->numRows - 1);
 #ifdef DEBUG_PRINT
     printf("\nymin: %d ymax: %d\n", ymin, ymax);
 #endif
-    for (int y = ymin ; y < ymax; y++) {
+    for (int y = ymin ; y <= ymax; y++) {
         int xleft  = xLeft(pt, y);
         int xright = xRight(pt, y);
@@ -177,5 +177,5 @@
         x_d = xOfY(&pt[0], &pt[3], y);
     }
-    return (int) x_d;
+    return (int) (x_d + 0.5);
 }
 
@@ -266,8 +266,8 @@
     /* find pt0 the left most (bottom most) corner */
     int imin = 0;
-    double  min = pt[0].x;
+    int  min = (int) pt[0].x;
     int i;
-    for (i=0; i<4; i++) {
-        double x = pt[i].x;
+    for (i=1; i<4; i++) {
+        int x = pt[i].x;
         if ((x < min) ||
             ((x == min) && (pt[i].y < pt[imin].y))) {
@@ -285,6 +285,6 @@
     imin = 0;
     min = pt[0].y;
-    for (i=0; i<3; i++) {
-        double y = pt[i].y;
+    for (i=1; i<3; i++) {
+        int y = pt[i].y;
         if ((y < min) ||
             ((y == min) && (pt[i].x > pt[imin].x)) ) {
