From 46628665222e4c24a76a760f193dccadf866b1e8 Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Tue, 25 Nov 2014 13:34:26 +0100
Subject: [PATCH] Added an isInRange(AbsoluteDate) method.

This method allows caller to make sure a direct location call will not
generate an exception dut to date out of range.
---
 .../main/java/org/orekit/rugged/api/Rugged.java  | 16 ++++++++++++++++
 .../rugged/utils/SpacecraftToObservedBody.java   | 14 ++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/orekit/rugged/api/Rugged.java b/core/src/main/java/org/orekit/rugged/api/Rugged.java
index 214aa1d3..e75551c3 100644
--- a/core/src/main/java/org/orekit/rugged/api/Rugged.java
+++ b/core/src/main/java/org/orekit/rugged/api/Rugged.java
@@ -722,6 +722,22 @@ public class Rugged {
 
     }
 
+    /** Check if a date is in the supported range.
+     * <p>
+     * The supporte range is given by the {@code minDate} and
+     * {@code maxDate} construction parameters, with an {@code
+     * overshootTolerance} margin accepted (i.e. a date slightly
+     * before {@code minDate} or slightly after {@code maxDate}
+     * will be considered in range if the overshoot does not exceed
+     * the tolerance set at construction).
+     * </p>
+     * @param date date to check
+     * @return true if date is in the supported range
+     */
+    public boolean isInRange(final AbsoluteDate date) {
+        return scToBody.isInRange(date);
+    }
+
     /** Direct location of a sensor line.
      * @param sensorName name of the line sensor
      * @param lineNumber number of the line to localize on ground
diff --git a/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java b/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java
index c0c2db58..0d706bdd 100644
--- a/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java
+++ b/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java
@@ -250,10 +250,7 @@ public class SpacecraftToObservedBody implements Serializable {
         throws RuggedException {
 
         // check date range
-        if (minDate.durationFrom(date) > overshootTolerance) {
-            throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, date, minDate, maxDate);
-        }
-        if (date.durationFrom(maxDate) > overshootTolerance) {
+        if (!isInRange(date)) {
             throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, date, minDate, maxDate);
         }
 
@@ -264,4 +261,13 @@ public class SpacecraftToObservedBody implements Serializable {
 
     }
 
+    /** Check if a date is in the supported range.
+     * @param date date to check
+     * @return true if date is in the supported range
+     */
+    public boolean isInRange(final AbsoluteDate date) {
+        return (minDate.durationFrom(date) <= overshootTolerance) &&
+               (date.durationFrom(maxDate) <= overshootTolerance);
+    }
+
 }
-- 
GitLab