...
 
Commits (2)
......@@ -21,6 +21,9 @@
</properties>
<body>
<release version="10.1" date="TBD" description="TBD">
<action dev="evan" type="fix" issue="583">
Fix AbsoluteDate.compareTo() for future/past infinity.
</action>
<action dev="luc" type="fix" issue="588">
Fixed wrong handling of spacecraft states in multi-satellites orbit determination
and multi-satellite measurements generation.
......
......@@ -963,7 +963,12 @@ public class AbsoluteDate
* is before, simultaneous, or after the specified date.
*/
public int compareTo(final AbsoluteDate date) {
return Double.compare(durationFrom(date), 0);
final double duration = durationFrom(date);
if (!Double.isNaN(duration)) {
return Double.compare(duration, 0.0);
}
// both dates are infinity or one is NaN or both are NaN
return Double.compare(offset, date.offset);
}
/** {@inheritDoc} */
......
......@@ -628,17 +628,58 @@ public class AbsoluteDateTest {
Assert.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
Assert.assertTrue(AbsoluteDate.J2000_EPOCH.compareTo(AbsoluteDate.PAST_INFINITY) > 0);
Assert.assertTrue(AbsoluteDate.J2000_EPOCH.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.PAST_INFINITY) == 0);
Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.JULIAN_EPOCH) < 0);
Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.J2000_EPOCH) < 0);
Assert.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.JULIAN_EPOCH) > 0);
Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.J2000_EPOCH) > 0);
Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.PAST_INFINITY) > 0);
Assert.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.FUTURE_INFINITY) == 0);
Assert.assertTrue(Double.isInfinite(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.J2000_EPOCH)));
Assert.assertTrue(Double.isInfinite(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.PAST_INFINITY)));
Assert.assertTrue(Double.isInfinite(AbsoluteDate.PAST_INFINITY.durationFrom(AbsoluteDate.J2000_EPOCH)));
Assert.assertTrue(Double.isNaN(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.FUTURE_INFINITY)));
Assert.assertTrue(Double.isNaN(AbsoluteDate.PAST_INFINITY.durationFrom(AbsoluteDate.PAST_INFINITY)));
Assert.assertEquals("5881610-07-11T23:59:59.999", AbsoluteDate.FUTURE_INFINITY.toString());
Assert.assertEquals("-5877490-03-03T00:00:00.000", AbsoluteDate.PAST_INFINITY.toString());
Assert.assertEquals(true, AbsoluteDate.FUTURE_INFINITY.equals(AbsoluteDate.FUTURE_INFINITY));
Assert.assertEquals(true, AbsoluteDate.PAST_INFINITY.equals(AbsoluteDate.PAST_INFINITY));
Assert.assertEquals(false, AbsoluteDate.PAST_INFINITY.equals(AbsoluteDate.FUTURE_INFINITY));
Assert.assertEquals(false, AbsoluteDate.FUTURE_INFINITY.equals(AbsoluteDate.PAST_INFINITY));
}
@Test
public void testCompareTo() {
// check long time spans
AbsoluteDate epoch =
new AbsoluteDate(2000, 1, 1, 12, 0, 0, TimeScalesFactory.getTAI());
Assert.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(epoch) < 0);
Assert.assertTrue(epoch.compareTo(AbsoluteDate.JULIAN_EPOCH) > 0);
// check short time spans
AbsoluteDate d = epoch;
double epsilon = 1.0 - FastMath.nextDown(1.0);
Assert.assertTrue(d.compareTo(d.shiftedBy(epsilon)) < 0);
Assert.assertTrue(d.compareTo(d.shiftedBy(0)) == 0);
Assert.assertTrue(d.compareTo(d.shiftedBy(-epsilon)) > 0);
// check date with negative offset
d = epoch.shiftedBy(496891466)
.shiftedBy(0.7320114066633323)
.shiftedBy(-19730.732011406664);
// offset is 0 in d1
AbsoluteDate d1 = epoch.shiftedBy(496891466 - 19730);
Assert.assertTrue(d.compareTo(d1) < 0);
// decrement epoch, now offset is 0.999... in d1
d1 = d1.shiftedBy(-1e-16);
Assert.assertTrue("" + d.durationFrom(d1), d.compareTo(d1) < 0);
// check large dates
// these tests fail due to long overflow in durationFrom() Bug #584
// d = new AbsoluteDate(epoch, Long.MAX_VALUE);
// Assert.assertEquals(-1, epoch.compareTo(d));
// Assert.assertTrue(d.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
// d = new AbsoluteDate(epoch, Long.MIN_VALUE);
// Assert.assertTrue(epoch.compareTo(d) > 0);
// Assert.assertTrue(d.compareTo(AbsoluteDate.PAST_INFINITY) > 0);
}
@Test
......