gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master ee050f8: gal_box_overlap: new/better checks to


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master ee050f8: gal_box_overlap: new/better checks to test for no overlap
Date: Mon, 28 Jan 2019 21:33:50 -0500 (EST)

branch: master
commit ee050f8dfcb0c667e4069b294c7d2262ac1d65b5
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    gal_box_overlap: new/better checks to test for no overlap
    
    Until now, we weren't checking the special condition where both the first
    and last pixels are outside of image! This would causes crashes due to too
    large sizes for a dataset.
---
 lib/box.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/box.c b/lib/box.c
index 912f1e6..be97e3c 100644
--- a/lib/box.c
+++ b/lib/box.c
@@ -147,7 +147,7 @@ gal_box_border_from_center(double *center, size_t ndim, 
long *width,
    input image (fpixel_i[2] and lpixel_i[2]). But those first and last
    pixels don't necessarily lie within the image's boundaries. They can be
    outside of it or patially overlap with it (see examples below). The job
-   of this function is to corret for such situations and find the starting
+   of this function is to correct for such situations and find the starting
    and ending points of any overlap.
 
    It is assumed that your output (overlap) image's first pixel lies right
@@ -251,6 +251,11 @@ gal_box_overlap(long *naxes, long *fpixel_i, long 
*lpixel_i,
       */
       if(fpixel_i[i]<1)
         {
+          /* Along any dimension, if `lpixel_i' is also smaller than 1,
+             then there is no overlap. */
+          if(lpixel_i[i]<1) return 0;
+
+          /* Correct the coordinates. */
           fpixel_o[i] = -1*fpixel_i[i]+2;
           fpixel_i[i] = 1;
         }
@@ -269,6 +274,11 @@ gal_box_overlap(long *naxes, long *fpixel_i, long 
*lpixel_i,
         cropped image we should only fill upto c-n.*/
       if(lpixel_i[i]>naxes[i])
         {
+          /* Along any dimension, if `fpixel_i' is larger than the image
+             size, there is no overlap. */
+          if(fpixel_i[i]>naxes[i]) return 0;
+
+          /* Correct the coordinates. */
           lpixel_o[i] = width - (lpixel_i[i]-naxes[i]);
           lpixel_i[i] = naxes[i];
         }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]