public void DynamicMathTest() { Assert.AreEqual(DynamicMath.Add(0.5, 4), 4.5); Assert.AreEqual(DynamicMath.Add(0.5m, 4), 4.5m); Assert.AreEqual(DynamicMath.Add(0.5f, 4), 4.5f); Assert.AreEqual(DynamicMath.Add(2, 3), (int)5); Assert.AreEqual(DynamicMath.Subtract(0.5, 4), -3.5); Assert.AreEqual(DynamicMath.Subtract(0.5m, 4), -3.5m); Assert.AreEqual(DynamicMath.Subtract(0.5f, 4), -3.5f); Assert.AreEqual(DynamicMath.Subtract(2, 3), (int)-1); Assert.AreEqual(DynamicMath.Multiply(0.5, 4), 2.0); Assert.AreEqual(DynamicMath.Multiply(0.5m, 4), 2.0m); Assert.AreEqual(DynamicMath.Multiply(0.5f, 4), 2.0f); Assert.AreEqual(DynamicMath.Multiply(2, 3), (int)6); Assert.AreEqual(DynamicMath.Divide(6.0, 4), 1.5); Assert.AreEqual(DynamicMath.Divide(6.0m, 4), 1.5m); Assert.AreEqual(DynamicMath.Divide(6.0f, 4), 1.5f); Assert.AreEqual(DynamicMath.Divide(6, 3), (int)2); }
/// <summary> /// The actual cell-by-cell operations /// </summary> /// <param name="data"></param> /// <param name="id"></param> /// <returns></returns> protected override void CellOp(List <T[]> data, List <T[]> outputs, int id) { T val = outNodataVals[0]; // This is the raster and scalar case if (_scalar) { if (!data[0][id].Equals(inNodataVals[0])) { switch (_type) { // Choose your math operation case RasterOperators.MathOpType.Addition: val = DynamicMath.Add(data[0][id], _operand); break; case RasterOperators.MathOpType.Subtraction: val = DynamicMath.Subtract(data[0][id], _operand); break; case RasterOperators.MathOpType.Multipication: val = DynamicMath.Multiply(data[0][id], _operand); break; case RasterOperators.MathOpType.Division: val = DynamicMath.Divide(data[0][id], _operand); break; } } } // This is the two raster case else { bool masked = false; // Pure vector method. (This is the slow way) if (_hasVectorPolymask) { decimal[] ptcoords = ChunkExtent.Id2XY(id); List <long> shapes = _polymask.ShapesContainPoint((double)ptcoords[0], (double)ptcoords[1], _shapemask); if (shapes.Count == 0) { masked = true; } } // Rasterized vector method else if (_hasRasterizedPolymask && data.Count == 3 && data[2][id].Equals(inNodataVals[2])) { masked = true; } if (!data[0][id].Equals(inNodataVals[0]) && !data[1][id].Equals(inNodataVals[1]) && !masked) { switch (_type) { // Choose your math operation case RasterOperators.MathOpType.Addition: val = DynamicMath.Add(data[0][id], data[1][id]); break; case RasterOperators.MathOpType.Subtraction: val = DynamicMath.Subtract(data[0][id], data[1][id]); break; case RasterOperators.MathOpType.Multipication: val = DynamicMath.Multiply(data[0][id], data[1][id]); break; case RasterOperators.MathOpType.Division: val = DynamicMath.Divide(data[0][id], data[1][id]); break; } } } outputs[0][id] = val; }