From 952389886c0f65f93de38649792fe22f529d6f37 Mon Sep 17 00:00:00 2001
From: leonelrosano <leonelrosano@gmail.com>
Date: Wed, 7 Aug 2019 16:06:36 -0300
Subject: [PATCH] arreglo de bugs funciones R extra

---
 .../plotter/graph2D/graph2D.component.ts      | 144 +++++++++++++-----
 1 file changed, 104 insertions(+), 40 deletions(-)

diff --git a/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts b/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts
index ef96a556..791bbc4a 100755
--- a/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts	
+++ b/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts	
@@ -113,8 +113,11 @@ export class Graph2DComponent {
 
                         }
                         if (obj.conj.sets.fcod == "function(x)") {
+                           
                             var nom = jsonCanvas.funs[0].cod;
-                            var elemento2 = this.recursionfuncion(jsonCanvas.funs[0].sets, nom);
+                            var elemento2 = this.recursionfuncionCod(jsonCanvas.funs[0].sets, nom);
+                            console.log(elemento2)
+
                             obj.conj.sets.fcod = function (x) { return (eval(elemento2)) }
 
                             var funcionString = '';
@@ -129,11 +132,13 @@ export class Graph2DComponent {
 
                             obj.conj.sets.fdom = eval(funcionString);
 
+                            
+
 
                         }
 
                         var funcionGenerada = this.generarFuncion(jsonCanvas);
-                    
+                        
  
 
 
@@ -167,8 +172,8 @@ export class Graph2DComponent {
                         }
 
                         
-                        
                         let fun = eval(funcionGenerada);
+                   
 
                         var colores = ['violet', 'red', 'blue', 'orange', 'green','black']
                         var num = this.getRandomArbitrary(0, 5);
@@ -180,7 +185,6 @@ export class Graph2DComponent {
                         }else{
                             tipoGraf = 'polyline';
                         }
-                        console.log(obj.conj);
                         if(this.animation.boton && obj.conj.cod != 'Numer' && obj.conj.dom != 'Numer'){
                             if(this.conjunto.length == 1 && (this.conjunto[0].cod == 'Numer' || this.conjunto[0].dom == 'Numer')){
                                 this.conjunto = [];
@@ -229,6 +233,7 @@ export class Graph2DComponent {
                                             insertar = true;
                                         }
                                         if (insertar){
+                                            console.log("A")
                                             this.funciones.push({
                                                 id: 0,
                                                 sampler: 'builtIn',
@@ -243,7 +248,7 @@ export class Graph2DComponent {
                                         }
                                     } 
                                 }else{
-       
+                                    console.log("B")
                                         this.funciones.push({
 
                                             id: this.funciones.length,
@@ -302,7 +307,6 @@ export class Graph2DComponent {
                                         listValores.push(i)
                                     }
                                     let sinRepetidos = listValores.filter((valor, indiceActual, arreglo) => arreglo.indexOf(valor) === indiceActual);
-
                                     for (var fun2 of funcionesVer2019){
                                         let fun3 = eval(fun2);
                                         var insertar = false;
@@ -323,6 +327,7 @@ export class Graph2DComponent {
                                             insertar = true;
                                         }
                                         if (insertar){
+                                            console.log(fun3)
                                             this.funciones.push({
                                                 id: identificador,
                                                 sampler: 'builtIn',
@@ -337,6 +342,7 @@ export class Graph2DComponent {
                                         }
                                     } 
                                 }else{
+                                    console.log("D")
                                     this.funciones.push({
                                         id: identificador,
                                         sampler: 'builtIn',
@@ -970,6 +976,7 @@ export class Graph2DComponent {
                 exp.fun = 'Math.sqrt'
             }
 			expresion = ' ' + exp.fun + '(' + exp.args.map(e => this.generarExpresion(e)).join() + ') ';
+            
 
         } else if (exp.kind == 'tup') {
             expresion = ' (' + exp.exps.map(e => this.generarExpresion(e)).join() + ') ';
@@ -1001,22 +1008,21 @@ createListFunction = function (graph) {
     var nameFun = [];
     nameFun.push(fun1.fun);
     funciones = this.armarFuncion(fun1.bdy,graph,nameFun);
-
     for (var funs of funciones){
         for (var fun of graph.funs){
             if (fun.fun != fun1.fun){
                 funcionString = 'var ' + fun.fun + ' = function(' + fun.args.join() + '){\n return ' + this.generarExpresion(fun.bdy) + '}\n' + funcionString;
             }
         }
-        funcionString = 'var ' + fun1.fun + ' = function(' + fun1.args.join() + '){\n return ' + funs + '}\n' + funcionString;
 
+        funcionString = 'var ' + fun1.fun + ' = function(' + fun1.args.join() + '){\n return ' + funs + '}\n' + funcionString;
         funcionString += ';return ' + fun1.fun + '(' + fun1.args.join() + ');\n'
         grafica = fun1;
         funcionString = '(' + grafica.args.join() + ')=>{\n' + funcionString + '}';
+        
         arrayFunction.push(funcionString);   
         var funcionString = '';
     }
-    console.log(arrayFunction[0])
     return arrayFunction;
 }
 
@@ -1106,7 +1112,9 @@ generateFunctionAndExp = function (exp,graph,namefun6) {
                     myList.push(aux1);
                 }
             }
-        } else {
+        
+
+        }else {
 
             var lisA2 = this.generateFunctionAndExp(exp.exp1,graph,namefun6);
             var lisB2 = this.generateFunctionAndExp(exp.exp2,graph,namefun6);
@@ -1169,41 +1177,56 @@ generateFunctionAndExp = function (exp,graph,namefun6) {
             aux7[0]= aux27;
             aux7[1] = aux17;
             myList.push(aux7);
-        
-        }else if (exp.args[0].kind == 'app'){
-            var aux101 = [];
-            var aux1101 = exp.fun+'('+ exp.args.map(e => this.generarExpresion(e)).join() +')';
-            var aux2101 = 'N'
-            aux101[0]= aux2101;
-            aux101[1] = aux1101;
-            myList.push(aux101);
+        // }else if (exp.args[0].kind == 'app'){
+        //     var aux101 = [];
+        //     var aux1101 = exp.fun+'('+ exp.args.map(e => this.generarExpresion(e)).join() +')';
+        //     var aux2101 = 'N'
+        //     aux101[0]= aux2101;
+        //     aux101[1] = aux1101;
+        //     myList.push(aux101);
         
 
-        }else if(((exp.args[0].kind == 'cnd' || exp.args[0].kind == 'bop') && (exp.args[0].exp1.kind == 'app' || exp.args[0].exp2.kind == 'app' )) || (exp.args[0].kind == 'uop' && exp.args[0].exp.kind == 'app') ){
+        // }else if(((exp.args[0].kind == 'cnd' || exp.args[0].kind == 'bop') && (exp.args[0].exp1.kind == 'app' || exp.args[0].exp2.kind == 'app' )) || (exp.args[0].kind == 'uop' && exp.args[0].exp.kind == 'app') ){
+        //     var aux102 = [];
+        //     var aux1102 = exp.fun+'('+ exp.args.map(e => this.generarExpresion(e)).join() +')';
+        //     var aux2102 = 'N'
+        //     aux102[0]= aux2102;
+        //     aux102[1] = aux1102;
+        //     myList.push(aux102);
+        } else if(JSON.stringify(exp.args[0]).indexOf("app") != -1){ 
+            console.log("Entro");
+            exp.args[0] = this.recorrerArgumentos(exp.args[0]);
             var aux102 = [];
             var aux1102 = exp.fun+'('+ exp.args.map(e => this.generarExpresion(e)).join() +')';
             var aux2102 = 'N'
             aux102[0]= aux2102;
             aux102[1] = aux1102;
-            myList.push(aux102);
+            myList.push(aux102);        
         }else{ 
 
-            if(!namefun6.includes(exp.fun)){
-
+               
 
+            var nomFun = exp.fun+exp.args.map(e => this.generarExpresion(e)).join()
+            if(!namefun6.includes(nomFun)){
                 var ListnameFNew = namefun6;
-                ListnameFNew.push(exp.fun);
+
+                ListnameFNew.push(nomFun);
                 for (var fun5 of graph.funs){
                     if(fun5.fun == exp.fun){
-                        fun5.bdy.args = exp.args;
-                         myList = this.generateFunctionAndExp(fun5.bdy,graph,ListnameFNew);
+
+                        myList = this.generateFunctionAndExp(fun5.bdy,graph,ListnameFNew);
+                        for(var iter of myList){
+                            iter[1] = iter[1].replace(/x/g,exp.args.map(e => this.generarExpresion(e)).join())
+                        }
+
+
                     }
                 }
             }else{
 
                 var aux76 = [];
                 aux76[0] = 'N';
-                aux76[1] = exp.fun + "("+exp.args.map(e => this.generarExpresion(e)).join()+")";
+                aux76[1] = exp.fun+'('+exp.args.map(e => this.generarExpresion(e)).join()+')';
                 myList.push(aux76);
             }
         }
@@ -1239,6 +1262,29 @@ generateFunctionAndExp = function (exp,graph,namefun6) {
     return myList;
 }
 
+recorrerArgumentos = function(argumento){
+    if(argumento.kind == 'app'){
+        if ((argumento.fun == 'Math.cos') || (argumento.fun == 'cos')){
+            argumento.fun = 'Math.cos';
+        }else if((argumento.fun == 'Math.sin') || (argumento.fun == 'sin')){
+            argumento.fun = 'Math.sin';
+        }else if((argumento.fun == 'Math.round') || (argumento.fun == 'round')){
+            argumento.fun = 'Math.round';
+        }else if((argumento.fun == 'Math.sqrt') || (argumento.fun == 'sqrt')){
+            argumento.fun = 'Math.sqrt';
+        }
+
+    }else if(argumento.kind == 'cnd'){
+        this.recorrerArgumentos(argumento.exp1)
+        this.recorrerArgumentos(argumento.exp2)
+    }else if(argumento.kind == 'bop'){
+        this.recorrerArgumentos(argumento.exp1)
+        this.recorrerArgumentos(argumento.exp2)
+    }else if(argumento.kind == 'uop'){
+        this.recorrerArgumentos(argumento.exp1)
+    }
+    return argumento;
+}
 /////////////////////
 
 createListExp = function (exp) {
@@ -1555,21 +1601,23 @@ createListExp = function (exp) {
         } else if (grf.cod == 'Z') {
             dominio += "\"baseCod\": \"Z\", \"cod\": \"Z\" ,";
             setf += "\"fcod\": \"Z\"";
-        } else if (grf.cod == 'N') {
+        } /*else if (grf.cod == 'N') {
             dominio += "\"baseCod\": \"N\", \"cod\": \"N\" ,";
             setf += "\"fcod\": \"N\"";
-        } else {
-            var nom = grf.cod;
-            if (Array.isArray(grf.sets[0][nom])) {
-                var arreglo = grf.sets[0][nom];
-                var arreglo2 = [];
-                for (var item of arreglo) {
-                    arreglo2.push("\"" + item + "\"");
+        } */else {
+            var nom1 = grf.cod;
+
+            if (Array.isArray(grf.sets[1][nom1])) {
+                var arreglo3 = grf.sets[1][nom1];
+                var arreglo4 = [];
+                for (var item of arreglo3) {
+                    arreglo4.push("\"" + item + "\"");
                 }
                 dominio += "\"baseCod\": \"N\", \"cod\": \"Numer\" ,";
-                setf += '\"fcod\":[' + arreglo2 + ']';
+                setf += '\"fcod\":[' + arreglo4 + ']';
             } else {
-                dominio += this.recursivoCod(grf.sets, nom);
+
+                dominio += this.recursivoCod(grf.sets, nom1);
                 setf += "\"fcod\": \"function(x)\"";
             }
         }
@@ -1595,6 +1643,22 @@ createListExp = function (exp) {
         return resul;
     }
 
+
+    recursionfuncionCod = function (func, nombre) {
+        var fun = func[1][nombre].set;
+        var resul = "";
+        if (fun == 'R' || fun == 'Z' || fun == 'N') {
+
+            resul += this.generarF(func[1][nombre].cond);
+
+        } else {
+
+            resul += this.generarF(func[1][nombre].cond) + " && " + this.recursionfuncionCod(func, fun);
+
+        }
+        return resul;
+    }
+
     recursivoDom = function (sets, nom) {
         var domin = "";
         if (sets[0][nom].set == 'R') {
@@ -1613,14 +1677,14 @@ createListExp = function (exp) {
 
     recursivoCod = function (sets, nom) {
         var coodo = "";
-        if (sets[0][nom].set == 'R') {
+        if (sets[1][nom].set == 'R') {
             coodo += "\"baseCod\": \"R\", \"cod\": \"Func\",";
-        } else if (sets[0][nom].set == 'Z') {
+        } else if (sets[1][nom].set == 'Z') {
             coodo += "\"baseCod\": \"Z\", \"cod\": \"Func\",";
-        } else if (sets[0][nom].set == 'N') {
+        } else if (sets[1][nom].set == 'N') {
             coodo += "\"baseCod\": \"N\", \"cod\": \"Func\",";
         } else {
-            var nombre = sets[0][nom].set;
+            var nombre = sets[1][nom].set;
             coodo += this.recursivoDom(sets, nombre);
         }
         return coodo;
-- 
GitLab