Skip to content

Commit

Permalink
Fixes a bug related to the implementation of the Real64.inv() functio…
Browse files Browse the repository at this point in the history
…n. It also refactors the Matrix4.fromArray() and it's now Matrix4.fromElements()
  • Loading branch information
racampos committed Jan 23, 2024
1 parent e1ef763 commit bbc4bc9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zk3d",
"version": "0.0.9",
"version": "0.12.0",
"description": "General-purpose 3D library compatible with o1js and Mina zkApps.",
"type": "module",
"main": "build/src/index.js",
Expand Down
37 changes: 19 additions & 18 deletions src/Matrix4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,25 @@ export class Matrix4 extends Struct({
);
}

fromArray(array: Real64[]) {
this.n11 = array[0];
this.n12 = array[1];
this.n13 = array[2];
this.n14 = array[3];
this.n21 = array[4];
this.n22 = array[5];
this.n23 = array[6];
this.n24 = array[7];
this.n31 = array[8];
this.n32 = array[9];
this.n33 = array[10];
this.n34 = array[11];
this.n41 = array[12];
this.n42 = array[13];
this.n43 = array[14];
this.n44 = array[15];
return this;
static fromElements(array: Real64[]) {
return new Matrix4({
n11: array[0],
n12: array[1],
n13: array[2],
n14: array[3],
n21: array[4],
n22: array[5],
n23: array[6],
n24: array[7],
n31: array[8],
n32: array[9],
n33: array[10],
n34: array[11],
n41: array[12],
n42: array[13],
n43: array[14],
n44: array[15]
});
}

toArray() {
Expand Down
2 changes: 1 addition & 1 deletion src/Real64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Real64 extends Struct({ integer: Int64 }) {
}

inv() {
return new Real64({ integer: Int64.from(Real64.SCALE).div(this.integer) });
return new Real64({ integer: Int64.from(Real64.SCALE).mul(Real64.SCALE).div(this.integer) });
}

neg() {
Expand Down

0 comments on commit bbc4bc9

Please sign in to comment.