Commit fe1d6c22 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Fix evaluation of matrixes

parent 42a693c4
......@@ -413,6 +413,15 @@ Object* Analyzer::eval(const Object* branch, bool resolve, const QSet<QString>&
nv->appendBranch(static_cast<MatrixRow*>(res));
}
ret=nv;
} else if(branch->type()==Object::matrixrow) {
const MatrixRow* v=static_cast<const MatrixRow*>(branch);
MatrixRow* nv=new MatrixRow;
MatrixRow::const_iterator it, itEnd=v->constEnd();
for(it=v->constBegin(); it!=itEnd; ++it) {
Object* res=eval(*it, resolve, unscoped);
nv->appendBranch(static_cast<MatrixRow*>(res));
}
ret=nv;
} else if(branch->type()==Object::apply) {
const Apply* c=static_cast<const Apply*>(branch);
Operator op = c->firstOperator();
......@@ -1208,6 +1217,8 @@ Object* Analyzer::simp(Object* root)
iterateAndSimp<Vector, Vector::iterator>(static_cast<Vector*>(root));
} else if(root->type()==Object::matrix) {
iterateAndSimp<Matrix, Matrix::iterator, MatrixRow>(static_cast<Matrix*>(root));
} else if(root->type()==Object::matrixrow) {
iterateAndSimp<MatrixRow, MatrixRow::iterator>(static_cast<MatrixRow*>(root));
} else if(root->type()==Object::list) {
iterateAndSimp<List, List::iterator>(static_cast<List*>(root));
} else if(root->type()==Object::apply) {
......
......@@ -498,11 +498,21 @@ void AnalitzaTest::testCorrection_data()
<< QStringLiteral("g:=(u, v)->f(u)+f(v)")
<< QStringLiteral("g(vector{1,2}, vector{3,4})");
QTest::newRow("aaa") << script << "30";
script.clear();
script << QStringLiteral("f := (w,zz) -> list{zz} | acs->forall(a<w : a@acs)");
script << QStringLiteral("f(2,3)");
QTest::newRow("lambda1") << script << "false";
script.clear();
script << QStringLiteral("f := x -> matrix { matrixrow { x, x } }");
script << QStringLiteral("f(90)");
QTest::newRow("matrix-f") << script << "matrix { matrixrow { 90, 90 } }";
script.clear();
script << QStringLiteral("rotate := angle -> matrix { matrixrow { cos(angle), -sin(angle) }, matrixrow { sin(angle), cos(angle) } }");
script << QStringLiteral("rotate(90) * vector { 20, 20 }");
QTest::newRow("rotate-vector") << script << "vector { -26.8414055946, 8.91846094943 }";
}
//testCalculate
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment