From 47b2679550e933e05e8ef632475e7fa95719f9b0 Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Wed, 20 Dec 2023 16:55:59 +0900 Subject: [PATCH] add AABB test --- src/foundation/math/AABB.test.ts | 16 ++++++++++++++++ src/foundation/math/AABB.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/foundation/math/AABB.test.ts b/src/foundation/math/AABB.test.ts index b4d79d743..c28821e29 100644 --- a/src/foundation/math/AABB.test.ts +++ b/src/foundation/math/AABB.test.ts @@ -1,3 +1,4 @@ +import { Matrix44 } from './Matrix44'; import { AABB } from './AABB'; import { Vector3 } from './Vector3'; @@ -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); +}); diff --git a/src/foundation/math/AABB.ts b/src/foundation/math/AABB.ts index 71100a6f9..ff022a7fd 100644 --- a/src/foundation/math/AABB.ts +++ b/src/foundation/math/AABB.ts @@ -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) ); } }