public static bool SimplifySummands(ISignalSet signals) { bool changed = CollectSummands(signals); if (signals.Count < 2) { return(changed); } IAccumulator acc = null; for (int i = signals.Count - 1; i >= 0; i--) { Signal s = signals[i]; if (Std.IsConstantComplex(s)) { if (acc == null) { acc = Accumulator <IntegerValue, RationalValue> .Create(IntegerValue.AdditiveIdentity); } signals.RemoveAt(i); changed = true; acc = acc.Add(s.Value); } } if (acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity)) { signals.Insert(0, Std.DefineConstant(acc.Value)); } return(changed); }
public Observer(ICamera camera, int imageWidth, int imageHeight) { Camera = camera; Accumulator = new Accumulator(imageWidth, imageHeight); Camera.AspectRatio = (float)Accumulator.Width / Accumulator.Height; Camera.OnMoved += (_, _) => Accumulator.Clear(); Camera.Film.SampleRegistered += (_, sample) => Accumulator.Add(sample); }
public IAccumulator Add(IValueStructure operand) { object other; if (ValueConverter <T> .TryConvertLosslessFrom(operand, out other)) { _value = _value.Add((T)other); return(this); } else { IAccumulator acc = Escalate(operand.TypeId, _value, false); return(acc.Add(operand)); } }
public override void Step(T container, string selector) { var value = Accessor.Read(container, selector); if (value != null) { if (_accumulator == null) { _accumulator = AccumulatorFactory.Create(value.GetType()); } try { _accumulator.Add(value); } catch (FormatException) { } catch (InvalidCastException) { } } }
public static bool SimplifySummands(ISignalSet signals) { bool changed = CollectSummands(signals); if (signals.Count < 2) { return(changed); } IAccumulator acc = null; for (int i = signals.Count - 1; i > 0; i--) //don't touch first item! { Signal s = signals[i]; if (Std.IsConstantComplex(s)) { if (acc == null) { acc = Accumulator <IntegerValue, RationalValue> .Create(IntegerValue.AdditiveIdentity); } signals.RemoveAt(i); changed = true; acc = acc.Add(s.Value); } } if (acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity)) { Signal first = signals[0]; if (Std.IsConstantComplex(first)) { acc = acc.Subtract(first.Value).Negate(); signals[0] = Std.DefineConstant(acc.Value); changed = true; } else { signals.Insert(1, Std.DefineConstant(acc.Value)); } } return(changed); }
static void Accumulate(IAccumulator x, int value) => x.Add(value);