Index: /issm/trunk/src/c/shared/Exp/IsInPoly.cpp
===================================================================
--- /issm/trunk/src/c/shared/Exp/IsInPoly.cpp	(revision 6964)
+++ /issm/trunk/src/c/shared/Exp/IsInPoly.cpp	(revision 6965)
@@ -22,4 +22,16 @@
 	double x0,y0;
 	double value;
+	double xmin=xc[0];
+	double xmax=xc[0];
+	double ymin=yc[0];
+	double ymax=yc[0];
+
+	/*Get extrema*/
+	for (i=1;i<numgrids;i++){
+		if(xc[i]<xmin) xmin=xc[i];
+		if(xc[i]>xmax) xmax=xc[i];
+		if(yc[i]<ymin) ymin=yc[i];
+		if(yc[i]>ymax) ymax=yc[i];
+	}
 
 	/*Go through all grids of the mesh:*/
@@ -35,5 +47,10 @@
 		/*pick up grid (x[i],y[i]) and figure out if located inside contour (xc,yc)*/
 		x0=x[i]; y0=y[i];
-		value=pnpoly(numgrids,xc,yc,x0,y0,edgevalue);
+		if(x0<xmin || x0>xmax || y0<ymin || y0>ymax){
+			value=0;
+		}
+		else{
+			value=pnpoly(numgrids,xc,yc,x0,y0,edgevalue);
+		}
 		VecSetValues(in,1,&i,&value,INSERT_VALUES);
 	}
