コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Observer.cs プロジェクト: atharkes/raytracer
 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);
 }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        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) {
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 static void Accumulate(IAccumulator x, int value) => x.Add(value);