Index: trunk/psastro/src/psastroLoadGlints.c
===================================================================
--- trunk/psastro/src/psastroLoadGlints.c	(revision 41338)
+++ trunk/psastro/src/psastroLoadGlints.c	(revision 41348)
@@ -152,4 +152,9 @@
             }
 
+            //do a rudimentary check of whether the glint enters the pixel FPA
+            if (!strcasecmp(glintType, "TOP")    && ((star->FP->y - glintLength) > 20000.))  continue;
+            if (!strcasecmp(glintType, "BOTTOM") && ((star->FP->y + glintLength) < -20000.))  continue;
+            if (!strcasecmp(glintType, "LEFT")   && ((star->FP->x + glintLength) < -20000.))  continue;
+            if (!strcasecmp(glintType, "RIGHT")  && ((star->FP->x - glintLength) > 20000.))  continue;
 
 	    psVector *x_glint = psVectorAlloc(2,PS_TYPE_F32);
@@ -179,4 +184,5 @@
 		        double yFPAs, yFPAe;
 		        psastroFindChipYedges (&yFPAs, &yFPAe, fpa, nChip);
+		        if (yFPAs > yFPAe) PS_SWAP (yFPAs, yFPAe);
 
   		        xFPA0 = star->FP->x;
@@ -204,4 +210,5 @@
 		        double yFPAs, yFPAe;
 		        psastroFindChipYedges (&yFPAs, &yFPAe, fpa, nChip);
+		        if (yFPAs > yFPAe) PS_SWAP (yFPAs, yFPAe);
 
   		        xFPA0 = star->FP->x;
@@ -218,4 +225,5 @@
 	        x_glint->data.F32[1] = xFPA1;
 	        y_glint->data.F32[1] = yFPA1;
+
 
                 //we need to loop over each corner to select the chips that can have the glint on it
@@ -243,4 +251,5 @@
 		        if (yFPA0 > yFPAe) continue;
 		        if (yFPA1 < yFPAs) continue;
+
 
                         //find the y-coord positions for this chip
@@ -322,10 +331,11 @@
 
 		        // FPA coordinates of intersections with chip edges 
-		        double yFPAs, yFPAe;
-		        psastroFindChipYedges (&yFPAs, &yFPAe, fpa, nChip);
-
-  		        xFPA0 = yFPAe;
+		        double xFPAs, xFPAe;
+		        psastroFindChipXedges (&xFPAs, &xFPAe, fpa, nChip);
+		        if (xFPAs > xFPAe) PS_SWAP (xFPAs, xFPAe);
+
+  		        xFPA0 = xFPAe;
 		        yFPA0 = star->FP->y;
-                        glintLength-= (star->FP->x-yFPAe);
+                        glintLength-= (star->FP->x-xFPAe);
                     }
 
@@ -347,10 +357,11 @@
 
 		        // FPA coordinates of intersections with chip edges 
-		        double yFPAs, yFPAe;
-		        psastroFindChipYedges (&yFPAs, &yFPAe, fpa, nChip);
-
-  		        xFPA0 = yFPAs;
+		        double xFPAs, xFPAe;
+		        psastroFindChipXedges (&xFPAs, &xFPAe, fpa, nChip);
+		        if (xFPAs > xFPAe) PS_SWAP (xFPAs, xFPAe);
+
+  		        xFPA0 = xFPAs;
 		        yFPA0 = star->FP->y;
-                        glintLength-= (yFPAs-star->FP->x);
+                        glintLength-= (xFPAs-star->FP->x);
                     }
 
@@ -431,4 +442,5 @@
 		   	
 		   	fprintf (stderr, "glint %s : %d %f,%f to %f,%f (%f %f %f)\n", glintType, nChip, xChip0, yChip0, xChip1, yChip1, glint_length, glintWidth, chip_angle);
+
 		   	psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
 		   	glint->data.F32[0] = xChip0;
