Skip to content

Commit 2b1cf3a

Browse files
committed
Added some tests
1 parent 03ed03b commit 2b1cf3a

8 files changed

Lines changed: 86 additions & 9 deletions

File tree

dist/CommentCoreLibrary.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ var CommentUtils;
265265
Matrix3D.identity = function () {
266266
return new Matrix3D([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
267267
};
268+
Matrix3D.createScaleMatrix = function (xscale, yscale, zscale) {
269+
return new Matrix3D([xscale, 0, 0, 0, 0, yscale, 0, 0, 0, 0, zscale, 0, 0, 0, 0, 1]);
270+
};
268271
Matrix3D.createRotationMatrix = function (xrot, yrot, zrot) {
269272
var DEG2RAD = Math.PI / 180;
270273
var yr = yrot * DEG2RAD;
@@ -277,7 +280,9 @@ var CommentUtils;
277280
(-SIN(yr) * COS(zr)), (-SIN(yr) * SIN(zr)), COS(yr), 0,
278281
0, 0, 0, 1
279282
];
280-
return new Matrix3D(matrix);
283+
return new Matrix3D(matrix.map(function (v) {
284+
return Math.round(v * 1e10) * 1e-10;
285+
}));
281286
};
282287
return Matrix3D;
283288
}());
@@ -805,6 +810,9 @@ var CommentUtils;
805810
Matrix3D.identity = function () {
806811
return new Matrix3D([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
807812
};
813+
Matrix3D.createScaleMatrix = function (xscale, yscale, zscale) {
814+
return new Matrix3D([xscale, 0, 0, 0, 0, yscale, 0, 0, 0, 0, zscale, 0, 0, 0, 0, 1]);
815+
};
808816
Matrix3D.createRotationMatrix = function (xrot, yrot, zrot) {
809817
var DEG2RAD = Math.PI / 180;
810818
var yr = yrot * DEG2RAD;
@@ -817,7 +825,9 @@ var CommentUtils;
817825
(-SIN(yr) * COS(zr)), (-SIN(yr) * SIN(zr)), COS(yr), 0,
818826
0, 0, 0, 1
819827
];
820-
return new Matrix3D(matrix);
828+
return new Matrix3D(matrix.map(function (v) {
829+
return Math.round(v * 1e10) * 1e-10;
830+
}));
821831
};
822832
return Matrix3D;
823833
}());

dist/CommentCoreLibrary.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/core/Utils_spec.coffee

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict'
2+
describe 'CommentUtils', ->
3+
describe 'Matrix3D', ->
4+
describe 'identity', ->
5+
it 'returns identity matrix', ->
6+
expect(CommentUtils.Matrix3D.identity().isIdentity()).toBe true
7+
8+
describe 'createScaleMatrix', ->
9+
it 'returns identity matrix', ->
10+
expect(CommentUtils.Matrix3D.createScaleMatrix(1, 1, 1).isIdentity()).toBe true
11+
12+
it 'returns proper scale matrix', ->
13+
expect(CommentUtils.Matrix3D.createScaleMatrix(1, 2, 3).flatArray).toEqual [1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1]
14+
15+
describe 'createRotationMatrix', ->
16+
it 'returns identity matrix if no rotation', ->
17+
expect(CommentUtils.Matrix3D.createRotationMatrix(0, 0, 0).isIdentity()).toBe true
18+
19+
it 'returns identity matrix if rotating 360 degrees', ->
20+
expect(CommentUtils.Matrix3D.createRotationMatrix(360, 0, 0).isIdentity()).toBe true
21+
expect(CommentUtils.Matrix3D.createRotationMatrix(0, 360, 0).isIdentity()).toBe true
22+
expect(CommentUtils.Matrix3D.createRotationMatrix(0, 0, 360).isIdentity()).toBe true
23+
24+
describe 'constructor', ->
25+
it 'throws error if constructed improper dimensions', ->
26+
expect( => new CommentUtils.Matrix3D([1, 2, 3])).toThrow()
27+
28+
describe 'instance API', ->
29+
m = null
30+
n = null
31+
mdotn = null
32+
beforeEach ->
33+
m = new CommentUtils.Matrix3D [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]
34+
n = CommentUtils.Matrix3D.createScaleMatrix 6, 7, 8
35+
mdotn = new CommentUtils.Matrix3D [6, 14, 24, 4, 30, 42, 56, 8, 54, 0, 8, 2, 18, 28, 40, 6]
36+
37+
it 'gets flatArray', ->
38+
expect(m.flatArray).toEqual [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]
39+
40+
it 'cannot set flatArray', ->
41+
expect( => m.flatArray = []).toThrow()
42+
43+
it 'checks identity', ->
44+
expect(m.isIdentity()).toBe false
45+
46+
it 'dot product', ->
47+
expect(m.dot(n).equals mdotn).toBe true
48+
49+
it 'toCss', ->
50+
expect(n.toCss()).toBe 'matrix3d(6,0,0,0,0,7,0,0,0,0,8,0,0,0,0,1)'

src/core/Comment.js

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/Comment.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/CommentFactory.js

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/CommentFactory.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/Utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module CommentUtils {
1313
return new Matrix3D([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
1414
};
1515

16+
public static createScaleMatrix:Function = function (xscale:number, yscale:number, zscale:number):Matrix3D {
17+
return new Matrix3D([xscale, 0, 0, 0, 0, yscale, 0, 0, 0, 0, zscale, 0, 0, 0, 0, 1]);
18+
};
19+
1620
public static createRotationMatrix:Function = function (xrot:number, yrot:number, zrot:number):Matrix3D {
1721
// Courtesy of @StarBrilliant, re-adapted for general case
1822
var DEG2RAD = Math.PI/180;
@@ -26,7 +30,10 @@ module CommentUtils {
2630
(-SIN(yr) * COS(zr)) , (-SIN(yr) * SIN(zr)) , COS(yr) , 0,
2731
0 , 0 , 0 , 1
2832
];
29-
return new Matrix3D(matrix);
33+
// Do some rounding
34+
return new Matrix3D(matrix.map(function (v) {
35+
return Math.round(v * 1e10) * 1e-10;
36+
}));
3037
};
3138

3239
/**

0 commit comments

Comments
 (0)