示例#1
0
        public void ReduceMultiplyingTest()
        {
            EvalSettings evalSettings = new EvalSettings();

            evalSettings.EvalFuncs = false;

            // 14 + 0 * sin ( 0.3 + 0.5 )
            E expr = E.Sum(E.NumConst(14), E.Mul(E.NumConst(0), E.Sin(E.Sum(E.NumConst(0.3), E.NumConst(0.5)))));
            E r    = expr.Evaluate(evalSettings);

            Assert.IsTrue(r is NumericConstant);
            Assert.IsTrue((r as NumericConstant).Value == 14);

            // 1988 + 0.5 * cos ( a ) * 2
            expr = E.Sum(E.NumConst(1988), E.Mul(E.NumConst(0.5), E.Cos(E.Num("a")), E.NumConst(2)));
            r    = expr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Sum);
            Assert.IsTrue((r as MultipleOp).Operands [1] is FuncCall);
        }
示例#2
0
        public void MatrixEvaluationTest()
        {
            EvalSettings evalSettings = new EvalSettings();

            evalSettings.EvalFuncs = false;

            Mat4 rotX30 = Mat4.RotX(30);
            Mat4 trans  = Mat4.Trans(new double3(2, 3, 4));
            Mat4 r      = rotX30 * trans;

            r = r.Evaluate(evalSettings);

            //evalSettings = new EvalSettings ( "phi", 30, "theta", 60, "psi", 90.0 );
            Mat4 rotX = Mat4.RotX(E.Num("phi"));
            Mat4 rotY = Mat4.RotY(E.Num("theta"));
            Mat4 rotZ = Mat4.RotZ(E.Num("psi"));

            r = rotX * rotY * rotZ;
            r = r.Evaluate(evalSettings);
            r = r.Transposed;
        }
示例#3
0
        public void EvaluateTest()
        {
            E            numExpr      = E.Num("a", 14.0);
            E            vecExpr      = E.Vec("v", new double4(2, 3, 4, 5));
            EvalSettings evalSettings = new EvalSettings(true);
            E            r            = numExpr.Evaluate(evalSettings);

            Assert.IsTrue(r is NumericConstant);

            // -a
            E negatedExpr = E.Negate(numExpr);

            r = negatedExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is NumericConstant);
            Assert.IsTrue((r as NumericConstant).Value == -14);

            // -v
            negatedExpr = E.Negate(vecExpr);
            r           = negatedExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is Variable);
            Assert.IsTrue((r as Variable).Value is double4);
            Assert.IsTrue(( double4 )(r as Variable).Value == new double4(-2, -3, -4, -5));

            // sin ( a )
            E funcExpr = E.Sin(numExpr);

            r = funcExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is NumericConstant);
            Assert.IsTrue((r as NumericConstant).Value == Math.Sin(14.0));

            // cos ( b )
            E varExpr = E.Num("b");

            funcExpr = E.Cos(varExpr);
            r        = funcExpr.Evaluate(evalSettings);
            Assert.IsFalse(r is NumericConstant);

            // v.y
            E propAccess = vecExpr.Prop("y");

            r = propAccess.Evaluate(evalSettings);
            Assert.IsTrue(r is NumericConstant);
            Assert.IsTrue((r as NumericConstant).Value == 3);

            // a = 1988, b = numeric unknown
            // 14 + a + b
            E sumExpr = E.Sum(E.NumConst(14.0), E.Num("a", 1988), E.Num("b"));

            r = sumExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Sum);
            Assert.IsTrue((r as MultipleOp).Operands [0] is NumericConstant);
            Assert.IsTrue(((r as MultipleOp).Operands [0] as NumericConstant).Value == 2002);

            // v = { 1, 0, 0, 0 }
            // v2 = { 0, 1, 0, 0 }
            // n = vector unknown
            // v + v2 + n
            E vSumExpr = E.Sum(E.Vec("v", new double4(1, 0, 0, 0)), E.Vec("v2", double4.UnitY), E.Vec("n"));

            r = vSumExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Sum);
            Assert.IsTrue((r as MultipleOp).Operands [0] is Variable);
            Assert.IsTrue(( double4 )((r as MultipleOp).Operands [0] as Variable).Value == new double4(1, 1, 0, 1));

            // a = 14, b = numeric unknown
            // 1988 - a - b
            E subExpr = E.Sub(E.NumConst(1988), E.Num("a", 14.0), E.Num("b"));

            r = subExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Sum);
            Assert.IsTrue((r as MultipleOp).Operands [0] is NumericConstant);
            Assert.IsTrue(((r as MultipleOp).Operands [0] as NumericConstant).Value == 1974);

            // v = { 1, 0, 0, 0 }
            // v2 = { 0, 1, 0, 0 }
            // n = vector unknown
            // v - v2 - n
            E vSubExpr = E.Sub(E.Vec("v", new double4(1, 0, 0, 0)), E.Vec("v2", double4.UnitY), E.Vec("n"));

            r = vSubExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Sum);
            Assert.IsTrue((r as MultipleOp).Operands [0] is Variable);
            Assert.IsTrue(( double4 )((r as MultipleOp).Operands [0] as Variable).Value == new double4(1, -1, 0, 1));

            // a = 14, b = numeric unknown
            // 1988 % a % b
            E modExpr = E.Mod(E.NumConst(1988), E.Num("a", 14.0), E.Num("b"));

            r = modExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Mod);
            Assert.IsTrue((r as MultipleOp).Operands [0] is NumericConstant);
            Assert.IsTrue(((r as MultipleOp).Operands [0] as NumericConstant).Value == 0);

            // a = 14, b = numeric unknown
            // 1988 * a * b
            E mulExpr = E.Mul(E.NumConst(1988), E.Num("a", 14.0), E.Num("b"));

            r = mulExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Mul);
            Assert.IsTrue((r as MultipleOp).Operands [0] is NumericConstant);
            Assert.IsTrue(((r as MultipleOp).Operands [0] as NumericConstant).Value == 27832);

            // v = { 1, 2, 3, 1 }, b = numeric unknown
            // v * 14 * b
            E vMulExpr = E.Mul(E.Vec("v", new double4(1, 2, 3, 1)), E.NumConst(14), E.Num("b"));

            r = vMulExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Mul);
            Assert.IsTrue((r as MultipleOp).Operands [0] is Variable);
            Assert.IsTrue(( double4 )((r as MultipleOp).Operands [0] as Variable).Value == new double4(14, 28, 42, 1));

            // a = 14
            // 1988 / a
            E divExpr = E.Div(E.NumConst(1988), E.Num("a", 14.0));

            r = divExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is NumericConstant);
            Assert.IsTrue((r as NumericConstant).Value == 142);

            // a = 14, b = numeric unknown
            // a / b
            divExpr = E.Div(E.Num("a", 14.0), E.Num("b"));
            r       = divExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Div);
            Assert.IsTrue((r as MultipleOp).Operands [0] is NumericConstant);
            Assert.IsTrue(((r as MultipleOp).Operands [0] as NumericConstant).Value == 14);

            // v = { 1, 2, 3, 1 }
            // v / 14
            E vDivExpr = E.Div(E.Vec("v", new double4(1, 2, 3, 1)), E.NumConst(14));

            r = vDivExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is Variable);
            Assert.IsTrue(( double4 )(r as Variable).Value == new double4(1.0 / 14, 2.0 / 14, 3.0 / 14, 1));

            // v = { 1, 2, 3, 1 }, b = numeric unknown
            // v / b
            vDivExpr = E.Div(E.Vec("v", new double4(1, 2, 3, 1)), E.Num("b"));
            r        = vDivExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is MultipleOp);
            Assert.IsTrue((r as MultipleOp).OpKind == MultipleOpKind.Div);
            Assert.IsTrue((r as MultipleOp).Operands [0] is Variable);
            Assert.IsTrue(( double4 )((r as MultipleOp).Operands [0] as Variable).Value == new double4(1.0, 2.0, 3.0, 1));

            // v1 = { 1, 2, 3, 1 }
            // v2 = { 3, 2, 1, 1 }
            // v1 & v2
            E vDotExpr = E.Dot(E.Vec("v1", new double4(1, 2, 3, 1)), E.Vec("v2", new double4(3, 2, 1, 1)));

            r = vDotExpr.Evaluate(evalSettings);
            Assert.IsTrue(r is NumericConstant);
            Assert.IsTrue((r as NumericConstant).Value == 10);

            // v1 = { 1, 2, 3, 1 }
            // v2 = { 3, 2, 1, 1 }
            // v1 x v2
            E vCrossExpr = E.Cross(E.Vec("v1", new double4(1, 2, 3, 1)), E.Vec("v2", new double4(3, 2, 1, 1)));

            r = vCrossExpr.Evaluate(evalSettings);
            Assert.IsTrue((r is Variable));
            Assert.IsTrue(( double4 )(r as Variable).Value == new double4(-4, 8, -4, 1));
        }