Skip to content

Commit ff6160b

Browse files
dakerfloryst
authored andcommitted
fix(Triangle): use TypedArray
1 parent 297d29c commit ff6160b

File tree

1 file changed

+7
-13
lines changed
  • Sources/Common/DataModel/Triangle

1 file changed

+7
-13
lines changed

Sources/Common/DataModel/Triangle/index.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import macro from 'vtk.js/Sources/macros';
1+
import macro, { TYPED_ARRAYS } from 'vtk.js/Sources/macros';
22
import vtkCell from 'vtk.js/Sources/Common/DataModel/Cell';
33
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
44
import vtkLine from 'vtk.js/Sources/Common/DataModel/Line';
@@ -614,24 +614,18 @@ function vtkTriangle(publicAPI, model) {
614614
* @param {Number[]} derivs - The derivatives.
615615
*/
616616
publicAPI.derivatives = (subId, pcoords, values, dim, derivs) => {
617-
const x0 = [];
618-
const x1 = [];
619-
const x2 = [];
620-
model.points.getPoint(0, x0);
621-
model.points.getPoint(1, x1);
622-
model.points.getPoint(2, x2);
617+
const x0 = model.points.getPoint(0);
618+
const x1 = model.points.getPoint(1);
619+
const x2 = model.points.getPoint(2);
623620

624621
const n = [];
625622
const v10 = [];
626623
const v20 = [];
627624
const v = [];
628625
computeNormal(x0, x1, x2, n);
629626

630-
for (let i = 0; i < 3; i++) {
631-
v10[i] = x1[i] - x0[i];
632-
v[i] = x2[i] - x0[i];
633-
}
634-
627+
vtkMath.subtract(x1, x0, v10);
628+
vtkMath.subtract(x2, x0, v);
635629
vtkMath.cross(n, v10, v20);
636630

637631
const lenX = vtkMath.normalize(v10); // check for degenerate triangle
@@ -658,7 +652,7 @@ function vtkTriangle(publicAPI, model) {
658652
const J = [v1[0] - v0[0], v1[1] - v0[1], v2[0] - v0[0], v2[1] - v0[1]];
659653

660654
// Compute inverse Jacobian (expects flat array)
661-
const JI = new Array(4).fill(0.0);
655+
const JI = macro.newTypedArray(TYPED_ARRAYS.Float64Array, 4);
662656
vtkMath.invertMatrix(J, JI, 2); // returns flat array [JI00, JI01, JI10, JI11]
663657

664658
// Compute derivatives

0 commit comments

Comments
 (0)