From 39a128bc99dfdfa06609662f67648010ecc3b7f2 Mon Sep 17 00:00:00 2001
From: Jesse Mapel <jam826@nau.edu>
Date: Tue, 2 Oct 2018 12:18:45 -0700
Subject: [PATCH] Added a check for impossible samples in ground to image
 (#113)

* Modified git ignore to ignore all iPython nb checkpoints

* Added a check in ls ground to image for samples outside the ccd.
---
 .gitignore                     | 4 ++--
 src/UsgsAstroLsSensorModel.cpp | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5acf88f..e9e8e08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,12 +4,12 @@ lib/*
 include/csm/*
 
 # iPython checkpoint items
-.ipynb_checkpoints/*
+.ipynb_checkpoints
 
 # Ignore any executables
 bin/*
 
-# Ignore any Max stuff
+# Ignore any Mac stuff
 .DS_Store
 
 *.cpython*
diff --git a/src/UsgsAstroLsSensorModel.cpp b/src/UsgsAstroLsSensorModel.cpp
index df705e1..d16eefe 100644
--- a/src/UsgsAstroLsSensorModel.cpp
+++ b/src/UsgsAstroLsSensorModel.cpp
@@ -299,6 +299,15 @@ csm::ImageCoord UsgsAstroLsSensorModel::groundToImage(
    double dz = ground_pt.z - calculatedPoint.z;
    double len = dx * dx + dy * dy + dz * dz;
 
+   // Check that the pixel is actually in the image
+   if ((calculatedPixel.samp < 0) ||
+       (calculatedPixel.samp > _data.m_TotalSamples)) {
+      throw csm::Error(
+         csm::Error::ALGORITHM,
+         "Ground point is not viewed by the image.",
+         "UsgsAstroLsSensorModel::groundToImage");
+   }
+
    // If the final correction is greater than 10 meters,
    // the solution is not valid enough to report even with a warning
    printf("%f\n", len);
-- 
GitLab