Esempio n. 1
0
        public void MathOp(MathOperationType operation, Imagem imagemB, int r)
        {
            if (imagemB != null)
            {
                int   width = this.MatrizCor.Width;
                int   height = this.MatrizCor.Height;
                int[] rgbA = { 0, 0, 0 }, rgbB = { 0, 0, 0 };
                int   x, y, canal;

                for (x = r; x < width - r; x++)
                {
                    for (y = r; y < height - r; y++)
                    {
                        for (canal = 0; canal < 3; canal++)
                        {
                            rgbA[canal] = this.MatrizCor.Matriz[x, y, canal];
                            rgbB[canal] = imagemB.MatrizCor.Matriz[x - r, y - r, canal];
                            switch (operation)
                            {
                            case MathOperationType.adicao:
                                rgbA[canal] += rgbB[canal];
                                break;

                            case MathOperationType.divisao:
                                rgbA[canal]  = (rgbA[canal] < 1) ? 1 : rgbA[canal];
                                rgbA[canal] /= rgbB[canal];
                                break;

                            case MathOperationType.multiplicacao:
                                rgbA[canal] *= rgbB[canal];
                                break;

                            case MathOperationType.subtracao:
                                rgbA[canal] -= rgbB[canal];
                                break;
                            }
                            this.MatrizCor.Matriz[x, y, canal] = rgbA[canal];
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <exception cref="System.ArgumentException">Throws when operationtype not exist in enum values.
        /// or double numbers args are NaN or Infinity</exception>
        /// <exception cref="System.ArithmeticException">Throws when lazyResult is false and mathematical operation return Infinity result.</exception>
        public MathOperation(double leftNumber, MathOperationType operationType,
                             double rightNumber, bool lazyResult = true)
        {
            if (!Enum.IsDefined(typeof(MathOperationType), operationType))
            {
                throw new ArgumentException($"Bad MathOperationType={operationType}");
            }

            if (double.IsNaN(leftNumber) || double.IsInfinity(leftNumber) ||
                double.IsNaN(rightNumber) || double.IsInfinity(rightNumber))
            {
                throw new ArgumentException($"Number args Error: leftNumber:{leftNumber}, rightNumber:{rightNumber}");
            }

            this.LeftNumber    = leftNumber;
            this.RightNumber   = rightNumber;
            this.OperationType = operationType;
            this.lazyResult    = lazyResult;
            if (lazyResult == false)
            {
                this._result = getMathResult();
            }
        }
Esempio n. 3
0
 public static bool Has(MathOperationType operationType, params Type[] operandTypes) =>
 !(Get(operationType, operandTypes) is null);
Esempio n. 4
0
 public static MathOperation Get(MathOperationType operationType, params Type[] operandTypes) =>
 GetAll(operandTypes).Find(o => o.OperationType == operationType);
Esempio n. 5
0
 public IOperationCalculator Resolve(MathOperationType operationType) =>
 resolvers.TryGetValue(operationType, out var resolver)
         ? resolver
         : throw new ArgumentException($"{nameof(IOperationCalculator)} for {operationType} is not defined");