public void TestSecondsDifference() { // Test same standard - both safe JulianDate first = new JulianDate(2451545.0); JulianDate second = first + Duration.FromSeconds(120000); Assert.AreEqual(120000, first.SecondsDifference(second)); Assert.AreEqual((second - first).TotalSeconds, first.SecondsDifference(second)); //Test same standard - both unsafe first = new JulianDate(2451545.0, TimeStandard.CoordinatedUniversalTime); second = first + Duration.FromSeconds(120000); second = new JulianDate(second.Day, second.SecondsOfDay, TimeStandard.CoordinatedUniversalTime); Assert.AreEqual(120000, first.SecondsDifference(second)); Assert.AreEqual((second - first).TotalSeconds, first.SecondsDifference(second)); // Test diff standard - one unsafe, one safe first = new JulianDate(2451545.0); second = first + Duration.FromSeconds(120000); JulianDate secondDiffStandard = second.ToTimeStandard(TimeStandard.CoordinatedUniversalTime); Assert.AreEqual(120000, first.SecondsDifference(secondDiffStandard)); Assert.AreEqual((secondDiffStandard - first).TotalSeconds, first.SecondsDifference(secondDiffStandard)); first = JulianDate.MinValue; second = JulianDate.MaxValue; Assert.AreEqual(((long)int.MaxValue - int.MinValue) * TimeConstants.SecondsPerDay, first.SecondsDifference(second)); }
/// <summary> /// Writes the time-tagged <see cref="UnitQuaternion"/> collection as an array in /// [Time, X, Y, Z, W] order. /// Times are epoch seconds since an epoch that is determined from the first date to be written. /// The epoch property is written as well. /// </summary> /// <param name="output">The stream to which to write the array.</param> /// <param name="propertyName">The name of the property to write.</param> /// <param name="dates">The dates at which the value is specified.</param> /// <param name="values">The corresponding value for each date.</param> /// <param name="startIndex">The index of the first element to use in the <paramref name="values"/> collection.</param> /// <param name="length">The number of elements to use from the <paramref name="values"/> collection.</param> public static void WriteUnitQuaternion(CesiumOutputStream output, string propertyName, IList <JulianDate> dates, IList <UnitQuaternion> values, int startIndex, int length) { if (dates.Count != values.Count) { throw new ArgumentException(CesiumLocalization.MismatchedNumberOfDatesAndValues, "values"); } JulianDate epoch = GetAndWriteEpoch(output, dates, startIndex, length); output.WritePropertyName(propertyName); output.WriteStartSequence(); int last = startIndex + length; for (int i = startIndex; i < last; ++i) { output.WriteValue(epoch.SecondsDifference(dates[i])); UnitQuaternion quaternion = values[i]; output.WriteValue(quaternion.X); output.WriteValue(quaternion.Y); output.WriteValue(quaternion.Z); output.WriteValue(quaternion.W); output.WriteLineBreak(); } output.WriteEndSequence(); }
/// <summary> /// Writes time-tagged <see cref="Cartographic"/> values as an array in [Time, Longitude, Latitude, Height] order. /// Times are epoch seconds since an epoch that is determined from the first date to be written. /// The epoch property is written as well. /// </summary> /// <param name="output">The stream to which to write the array.</param> /// <param name="propertyName">The name of the property to write.</param> /// <param name="dates">The dates at which the value is specified.</param> /// <param name="values">The corresponding value for each date.</param> /// <param name="startIndex">The index of the first element to use in the <paramref name="values"/> collection.</param> /// <param name="length">The number of elements to use from the <paramref name="values"/> collection.</param> public static void WriteCartographic(CesiumOutputStream output, string propertyName, IList <JulianDate> dates, IList <Cartographic> values, int startIndex, int length) { if (dates.Count != values.Count) { throw new ArgumentException(CesiumLocalization.MismatchedNumberOfDatesAndValues, "values"); } JulianDate epoch = GetAndWriteEpoch(output, dates, startIndex, length); output.WritePropertyName(propertyName); output.WriteStartSequence(); int last = startIndex + length; for (int i = startIndex; i < last; ++i) { output.WriteValue(epoch.SecondsDifference(dates[i])); Cartographic value = values[i]; output.WriteValue(value.Longitude); output.WriteValue(value.Latitude); output.WriteValue(value.Height); output.WriteLineBreak(); } output.WriteEndSequence(); }
/// <summary> /// Writes time-tagged <see cref="Motion<Cartesian>"/> values as an array in [Time, X, Y, Z, vX, vY, vZ] order. /// Times are epoch seconds since an epoch that is determined from the first date to be written. /// The epoch property is written as well. /// </summary> /// <param name="output">The stream to which to write the array.</param> /// <param name="propertyName">The name of the property to write.</param> /// <param name="dates">The dates at which the value is specified.</param> /// <param name="values">The corresponding value for each date.</param> /// <param name="startIndex">The index of the first element to use in the <paramref name="values"/> collection.</param> /// <param name="length">The number of elements to use from the <paramref name="values"/> collection.</param> public static void WriteCartesian3Velocity(CesiumOutputStream output, string propertyName, IList <JulianDate> dates, IList <Motion <Cartesian> > values, int startIndex, int length) { if (dates.Count != values.Count) { throw new ArgumentException(CesiumLocalization.MismatchedNumberOfDatesAndValues, "values"); } JulianDate epoch = GetAndWriteEpoch(output, dates, startIndex, length); output.WritePropertyName(propertyName); output.WriteStartSequence(); int last = startIndex + length; for (int i = startIndex; i < last; ++i) { output.WriteValue(epoch.SecondsDifference(dates[i])); Cartesian value = values[i].Value; Cartesian velocity = values[i].FirstDerivative; output.WriteValue(value.X); output.WriteValue(value.Y); output.WriteValue(value.Z); output.WriteValue(velocity.X); output.WriteValue(velocity.Y); output.WriteValue(velocity.Z); output.WriteLineBreak(); } output.WriteEndSequence(); }
public void TestSecondsDifferenceAtLeapSecond() { JulianDate leapSecond = new JulianDate(2453736, 43232, TimeStandard.InternationalAtomicTime); JulianDate utcDate = new JulianDate(2453736, 43232, TimeStandard.CoordinatedUniversalTime); Assert.AreEqual(-33, utcDate.SecondsDifference(leapSecond)); Assert.AreEqual(33, leapSecond.SecondsDifference(utcDate)); JulianDate secondBeforeLeapSecondUTC = leapSecond.SubtractSeconds(1).ToTimeStandard(TimeStandard.CoordinatedUniversalTime); JulianDate secondAfterLeapSecondUTC = leapSecond.AddSeconds(1).ToTimeStandard(TimeStandard.CoordinatedUniversalTime); Assert.AreEqual(2, secondBeforeLeapSecondUTC.SecondsDifference(secondAfterLeapSecondUTC)); Assert.AreEqual(2, secondAfterLeapSecondUTC.Subtract(secondBeforeLeapSecondUTC).Seconds); }
public void TestSecondsDifference() { // Test same standard - both safe JulianDate first = new JulianDate(2451545.0); JulianDate second = first + Duration.FromSeconds(120000); Assert.AreEqual(120000, first.SecondsDifference(second)); Assert.AreEqual((second - first).TotalSeconds, first.SecondsDifference(second)); //Test same standard - both unsafe first = new JulianDate(2451545.0, TimeStandard.CoordinatedUniversalTime); second = first + Duration.FromSeconds(120000); second = new JulianDate(second.Day, second.SecondsOfDay, TimeStandard.CoordinatedUniversalTime); Assert.AreEqual(120000, first.SecondsDifference(second)); Assert.AreEqual((second - first).TotalSeconds, first.SecondsDifference(second)); // Test diff standard - one unsafe, one safe first = new JulianDate(2451545.0); second = first + Duration.FromSeconds(120000); JulianDate secondDiffStandard = second.ToTimeStandard(TimeStandard.CoordinatedUniversalTime); Assert.AreEqual(120000, first.SecondsDifference(secondDiffStandard)); Assert.AreEqual((secondDiffStandard - first).TotalSeconds, first.SecondsDifference(secondDiffStandard)); }