Index: trunk/Ohana/src/opihi/dvo/ImageOps.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/ImageOps.c	(revision 2598)
+++ trunk/Ohana/src/opihi/dvo/ImageOps.c	(revision 3393)
@@ -9,6 +9,5 @@
   int *subset;
   int N, n, npts;
-  double r, d, x[4], y[4], Rmin, Rmax, Rmid;
-  double X[8], Y[8];
+  double r, d, X, Y, x[4], y[4], Rmin, Rmax, Rmid;
 
   if (RegionSelect) {
@@ -16,4 +15,5 @@
     Rmax = graph[0].coords.crval1 + 182.0;
     Rmid = 0.5*(Rmin + Rmax);
+    BuildChipMatch (image, Nimage);
   }
 
@@ -22,5 +22,5 @@
     trange = fabs (trange);
   }
-  status = InPic = TRUE;
+
   npts = 200;
   ALLOCATE (subset, int, npts);
@@ -29,4 +29,5 @@
     if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
     if (RegionSelect) {
+      if (!FindMosaicForImage (image, Nimage, i)) continue;
       /* project this image to screen display coords */
       x[0] = 0;           y[0] = 0;
@@ -34,38 +35,31 @@
       x[2] = image[i].NX; y[2] = image[i].NY;
       x[3] = 0;           y[3] = image[i].NY;
-      status = FALSE;
-      flipped = FALSE;
+      InPic = flipped = FALSE;
       for (j = 0; j < 4; j++) {
 	XY_to_RD (&r, &d, x[j], y[j], &image[i].coords);
-	while ((j == 0) && (r < Rmin)) { flipped = TRUE; r += 360.0; }
-	while ((j == 0) && (r > Rmax)) { flipped = TRUE; r -= 360.0; }
-	if ((j > 0) && flipped) {
-	  while (r < Rmid) r+= 360.0;
-	  while (r > Rmid) r-= 360.0;
+	/* use same side of 0,360 boundary for all corners */
+	if ((j == 0) && (r < Rmin)) flipped = TRUE; 
+	if ((j == 0) && (r > Rmax)) flipped = TRUE; 
+	while (flipped && (r < Rmid)) r+= 360.0;
+	while (flipped && (r > Rmid)) r-= 360.0;
+	status = RD_to_XY (&X, &Y, r, d, &graph[0].coords);
+
+	if (!status) continue;
+	if (X < graph[0].xmin) continue;
+	if (X > graph[0].xmax) continue;
+	if (Y < graph[0].ymin) continue;
+	if (Y > graph[0].ymax) continue;
+	subset[n] = i;
+	n++;
+	if (n > npts - 1) {
+	  npts += 200;
+	  REALLOCATE (subset, int, npts);
 	}
-	status |= RD_to_XY (&X[2*j], &Y[2*j], r, d, &graph[0].coords);
-	if (j > 0) {
-	  X[2*j - 1] = X[2*j];
-	  Y[2*j - 1] = Y[2*j];
-	}
+	break;
       }
-      X[7] = X[0];
-      Y[7] = Y[0];
-      InPic = FALSE;
-      for (j = 0; status && (j < 8); j+=2) {
-	if ((X[j] >= graph[0].xmin) && 
-	    (X[j] <= graph[0].xmax) && 
-	    (Y[j] >= graph[0].ymin) && 
-	    (Y[j] <= graph[0].ymax))
-	  InPic = TRUE;
-      }
-    }
-    if (InPic && status) {
-      subset[n] = i;
-      n++;
-      if (n > npts - 1) {
-	npts += 200;
-	REALLOCATE (subset, int, npts);
-      }
+      /** we miss any images which surround the region.  we are also
+	  missing the DIS images for which the corners don't touch
+	  the region, but which are needed for WRP images with
+	  corners touching the region **/
     }
   }
