/// <summary> /// Occurs on the next <see cref="Calculated"/> trajectory point. /// </summary> /// <param name="e"></param> protected virtual void OnCalculated(TrajectoryCalculatorEventArgs e) { if (Calculated == null) { return; } Calculated(this, e); }
/// <summary> /// Tries to calculate the desired <paramref name="results"/> at the specified <paramref name="timeQty"/>. /// </summary> /// <param name="timeQty"></param> /// <param name="results"></param> /// <returns></returns> public bool TryCalculate(IQuantity timeQty, out IDictionary <TrajectoryComponent, IQuantity> results) { results = _calculators.ToDictionary(c => c.Type, c => c.Calculate(_parameters, timeQty)); // Continue trying to calculate as long as we receive feedback in order to do so. var e = new TrajectoryCalculatorEventArgs(results); OnCalculated(e); return(e.Continue); }
/// <summary> /// <see cref="ITrajectoryCalculator.Calculated"/> observable handler. /// </summary> /// <param name="e"></param> protected override void OnNext(TrajectoryCalculatorEventArgs e) { Action <IQuantity> ofLength = qty => Assert.That(qty.Dimensions.AreCompatible(new[] { L.Meter }, true)); MaxRangeQty = e.Results.Verify(TrajectoryComponent.MaxRange).Verify(ofLength); MaxHeightQty = e.Results.Verify(TrajectoryComponent.MaxHeight).Verify(ofLength); var xQty = e.Results.Verify(TrajectoryComponent.X).Verify(ofLength); var yQty = e.Results.Verify(TrajectoryComponent.Y).Verify(ofLength); var item = Tuple.Create(xQty, yQty); /* The X and Range components may be unreliable especially once aerodynamic * resistance is factored in. But for this purpose this is sufficient. */ Continue = e.Continue = (Quantity)xQty < MaxRangeQty; _trajectory.Add(item); }
/// <summary> /// <see cref="ITrajectoryCalculator.Calculated"/> observable handler. /// </summary> /// <param name="e"></param> protected override void OnNext(TrajectoryCalculatorEventArgs e) { var m = L.Meter; var ms = T.Millisecond; Assert.That(e, Is.Not.Null); Assert.That(e.Continue, Is.True); var results = e.Results; results.TryVerify(TrajectoryComponent.Z, false); /* We expect a Y component, but are less concerned with its actual value at this moment, * only that the dimensions are correct. */ results.Verify(TrajectoryComponent.Y) .Verify(qty => Assert.That(qty.Dimensions.AreCompatible(new[] { m }))); results.Verify(TrajectoryComponent.X).Verify(Quantity.Zero(m)); results.Verify(TrajectoryComponent.MaxTime).Verify(Quantity.Zero(ms)); results.Verify(TrajectoryComponent.MaxHeight).Verify(Quantity.Zero(m)); results.Verify(TrajectoryComponent.MaxRange).Verify(Quantity.Zero(m)); }
/// <summary> /// Tries to calculate the desired <paramref name="results"/> at the specified <paramref name="timeQty"/>. /// </summary> /// <param name="timeQty"></param> /// <param name="results"></param> /// <returns></returns> public bool TryCalculate(IQuantity timeQty, out IDictionary<TrajectoryComponent, IQuantity> results) { results = _calculators.ToDictionary(c => c.Type, c => c.Calculate(_parameters, timeQty)); // Continue trying to calculate as long as we receive feedback in order to do so. var e = new TrajectoryCalculatorEventArgs(results); OnCalculated(e); return e.Continue; }
/// <summary> /// Occurs on the next <see cref="Calculated"/> trajectory point. /// </summary> /// <param name="e"></param> protected virtual void OnCalculated(TrajectoryCalculatorEventArgs e) { if (Calculated == null) return; Calculated(this, e); }
/// <summary> /// <see cref="ITrajectoryCalculator.Calculated"/> observable handler. /// </summary> /// <param name="e"></param> protected abstract void OnNext(TrajectoryCalculatorEventArgs e);