-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced.component.ts
More file actions
145 lines (121 loc) · 3.87 KB
/
Copy pathadvanced.component.ts
File metadata and controls
145 lines (121 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { Component, OnInit } from '@angular/core';
import { faCalculator } from '@fortawesome/free-solid-svg-icons';
import { Matrix } from 'src/app/matrix.model';
import { MatrixService } from 'src/app/matrix.service';
import { advanced_op_title, determinant_title, basic_op_title } from 'src/lgs/lg';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-advanced',
templateUrl: './advanced.component.html',
styleUrls: ['./advanced.component.css']
})
export class AdvancedComponent implements OnInit {
public matrixA: Matrix;
public matrixC: Matrix; // Auxiliar
public message: string;
public showResult: boolean;
public showMessage: boolean;
operator;
operationText;
iconBasic = faCalculator;
advancedText = basic_op_title;
determinantText = determinant_title;
closeResult() {
this.showResult = false;
}
ngClickGauss() {
this.operator = 'gss';
}
ngClickGaussJordan() {
this.operator = 'gsj';
}
ngClickDet() {
this.operator = 'det';
}
ngClickTrs() {
this.operator = 'trs';
}
ngClickInv() {
this.operator = 'inv';
}
constructor(private matrixService: MatrixService, private _Activatedroute: ActivatedRoute) {
this.operator = 'gss';
this.message = 'loading matrix...'
this.operator = this._Activatedroute.snapshot.paramMap.get("id");
if (this.operator != 'gss' && this.operator != 'gsj' && this.operator != 'det') {
this.operator = 'gss';
}
this.showResult = false;
this.showMessage = false;
this.matrixA = new Matrix(200, `A`, [[1.0, 1.0, 1.0, 1.0], [2.0, 1.0, 1.0, 1.0], [2.0, 2.0, 1.0, 1.0]]);
this.matrixA = new Matrix(200, `A`, [[1.0, 1.0, 1.0, 1.0], [2.0, 1.0, 1.0, 1.0], [2.0, 2.0, 1.0, 1.0], [0.0, 2.0, 2.0, 1.0]]);
}
private callGauss() {
this.matrixC = this.matrixService.OpGetGauss(this.matrixA);
this.checkStatus();
this.showResult = true;
}
private callGaussJordan() {
if (this.matrixA.getMatrixCols() !== this.matrixA.getMatrixRows()) {
this.matrixC = this.matrixService.OpGetGaussJordan(this.matrixA);
this.checkStatus();
this.showResult = true;
} else {
const dim = `Dimensions: A rows = ${this.matrixA.getMatrixRows()}, cols = ${this.matrixA.getMatrixCols()}`;
this.message = `Error: the last col is for the values (extended matrix). ${dim}`
this.showMessage = true;
}
}
private callInverse() {
if (this.matrixA.getMatrixCols() === this.matrixA.getMatrixRows()) {
this.matrixC = this.matrixService.OpGetInverse(this.matrixA);
this.checkStatus();
this.showResult = true;
} else {
const dim = `Dimensions: A rows = ${this.matrixA.getMatrixRows()}, cols = ${this.matrixA.getMatrixCols()}`;
this.message = `Error: This service only works for nxn matrices. ${dim}`
this.showMessage = true;
}
}
private callTranspose() {
this.matrixC = this.matrixService.getTransposeMatrix(this.matrixA);
this.checkStatus();
this.showResult = true;
}
private callDeterminants() {
this.matrixC = this.matrixService.OpGetDeterminant(this.matrixA);
this.checkStatus();
this.showResult = true;
}
private checkStatus() {
if (this.matrixC.getStatus() != 200) {
this.message = `Trying to connect... \n We don't found response from the server. Check ur connection or try later. Estatus: ${this.matrixC.getStatus()}`
this.showMessage = true;
}
}
submit() {
this.showResult = true;
this.showMessage = false;
switch (this.operator) {
case 'gss':
this.callGauss();
break;
case 'gsj':
this.callGaussJordan();
break;
case 'inv':
this.callInverse();
break;
case 'det':
this.callDeterminants();
break;
case 'trs':
this.callTranspose();
break;
default:
break;
}
}
ngOnInit() {
}
}