Skip to content

Commit

Permalink
add AABB test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Dec 20, 2023
1 parent f52177b commit 47b2679
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/foundation/math/AABB.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Matrix44 } from './Matrix44';
import { AABB } from './AABB';
import { Vector3 } from './Vector3';

Expand All @@ -14,3 +15,18 @@ test('AABB clone method works properly', () => {
const aabb = new AABB();
expect(aabb.isVanilla()).toBe(true);
});

test('AABB multiply', () => {
const aabb = new AABB();
aabb.addPosition(Vector3.fromCopyArray([1, 0, 0]));
aabb.addPosition(Vector3.fromCopyArray([0, 1, 0]));

const aabb2 = new AABB();
AABB.multiplyMatrixTo(Matrix44.rotateZ(Math.PI / 4), aabb, aabb2);

console.log(aabb2.toStringApproximately());

expect(aabb2.minPoint.isEqual(Vector3.fromCopy3(-0.7071068, 0, 0), 0.001)).toBe(true);
expect(aabb2.maxPoint.isEqual(Vector3.fromCopy3(0.7071068, 1.4142135, 0), 0.001)).toBe(true);
expect(aabb2.centerPoint.isEqual(Vector3.fromCopy3(0, 0.7071068, 0), 0.001)).toBe(true);
});
4 changes: 2 additions & 2 deletions src/foundation/math/AABB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ export class AABB {
this.__min.toStringApproximately() +
'\n' +
'centerPoint: ' +
this.__centerPoint.toStringApproximately() +
this.centerPoint.toStringApproximately() +
'\n' +
'lengthCenterToCorner: ' +
MathUtil.financial(this.__lengthCenterToCorner)
MathUtil.financial(this.lengthCenterToCorner)
);
}
}

0 comments on commit 47b2679

Please sign in to comment.