Skip to content

Commit

Permalink
#6 add basic Matrix class
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspietravallo committed Jul 18, 2022
1 parent 2bde49c commit f759430
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions coverage/coverage-summary.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"total": {"lines":{"total":944,"covered":865,"skipped":0,"pct":91.63},"statements":{"total":1011,"covered":926,"skipped":0,"pct":91.59},"functions":{"total":219,"covered":203,"skipped":0,"pct":92.69},"branches":{"total":578,"covered":468,"skipped":0,"pct":80.97}}
,"/Users/tomaspietravallo/Documents/GitHub/sparkar-volts/volts.ts": {"lines":{"total":944,"covered":865,"skipped":0,"pct":91.63},"functions":{"total":219,"covered":203,"skipped":0,"pct":92.69},"statements":{"total":1011,"covered":926,"skipped":0,"pct":91.59},"branches":{"total":578,"covered":468,"skipped":0,"pct":80.97}}
{"total": {"lines":{"total":949,"covered":870,"skipped":0,"pct":91.68},"statements":{"total":1017,"covered":932,"skipped":0,"pct":91.64},"functions":{"total":222,"covered":206,"skipped":0,"pct":92.79},"branches":{"total":580,"covered":470,"skipped":0,"pct":81.03}}
,"/Users/tomaspietravallo/Documents/GitHub/sparkar-volts/volts.ts": {"lines":{"total":949,"covered":870,"skipped":0,"pct":91.68},"functions":{"total":222,"covered":206,"skipped":0,"pct":92.79},"statements":{"total":1017,"covered":932,"skipped":0,"pct":91.64},"branches":{"total":580,"covered":470,"skipped":0,"pct":81.03}}
}
18 changes: 18 additions & 0 deletions tests/matrix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Matrix } from '../volts';

describe('matrix construction', () => {
test('construct', () => {
expect(() => new Matrix([0,0,0], [0,0,0], [0,0,0])).not.toThrow();
});
test('error', () => {
expect(() => new Matrix([1,2,3], [1,2], [1])).toThrow();
expect(() => new Matrix([1,2,3])).toThrow();
expect(() => new Matrix([1], [2], [3])).toThrow();
})
});

describe('utils', () => {
test('toString', () => {
expect(new Matrix([0,0,0], [0,0,0], [0,0,0]).toString()).toEqual('0,0,0,0,0,0,0,0,0');
})
})
20 changes: 20 additions & 0 deletions volts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,24 @@ Vector.prototype.rotate = function <D extends number>(a: number): Vector<D> {

//#endregion

//#region Matrix

export class Matrix {
values: number[][];
constructor(...args: number[][] ) {
this.values = args;
if (!args.every((arr) => arr.length === args.length)) {
throw new Error(`@ Volts.Matrix arguments do not correspond to Square matrix. args: ${args}`);
};
}
toString() {
return this.values.toString();
}
}

//#endregion


//#region Quaternion

type QuaternionArgRest = [number, number, number, number] | [number[]] | [Quaternion] | [];
Expand Down Expand Up @@ -2139,6 +2157,8 @@ export class Object3D<T extends SceneObjectBase = any> {
throw new Error(`@ Volts.createPhysicsSolver: Solver "${args.solver}" is not implemented `);
};

// Resolve collisions

// if (obj.pos.y < args.floor) {
// obj.pos.y = args.floor;
// }
Expand Down

0 comments on commit f759430

Please sign in to comment.