Skip to content

Commit 3d32206

Browse files
committed
Added Vector3Utils.ceil test. Fixed up AABBUtils tests to use toEqual since Vector3Utils.equals requires an extra helper to stringify the expected/actual inputs
1 parent dbf912c commit 3d32206

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

libraries/math/src/aabb/coreHelpers.test.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ import type { Vector3 } from '@minecraft/server';
99
import { VECTOR3_FORWARD, VECTOR3_ONE, VECTOR3_ZERO, Vector3Utils } from '../vector3/coreHelpers.js';
1010
import { AABB, AABBUtils } from './coreHelpers.js';
1111

12-
function expectVector3(expected: Vector3, actual: Vector3) {
13-
return expect(
14-
Vector3Utils.equals(expected, actual),
15-
`Expected ${Vector3Utils.toString(expected)} but actual is ${Vector3Utils.toString(actual)}`
16-
);
17-
}
18-
1912
describe('AABB factories', () => {
2013
it('successfully reports invalid AABB when created from identical corner points', () => {
2114
const aabb = AABBUtils.createFromCornerPoints(VECTOR3_ONE, VECTOR3_ONE);
@@ -165,42 +158,42 @@ describe('AABB BlockVolume operations', () => {
165158
it('successfully creates a BlockVolume when AABB extents are VECTOR3_ONE', () => {
166159
const aabb: AABB = { center: VECTOR3_ZERO, extents: VECTOR3_ONE };
167160
const blockVolume = AABBUtils.getBlockVolume(aabb);
168-
expectVector3({ x: -1.0, y: -1.0, z: -1.0 }, blockVolume.from).toBe(true);
169-
expectVector3({ x: 1.0, y: 1.0, z: 1.0 }, blockVolume.to).toBe(true);
161+
expect(blockVolume.from).toEqual({ x: -1.0, y: -1.0, z: -1.0 });
162+
expect(blockVolume.to).toEqual({ x: 1.0, y: 1.0, z: 1.0 });
170163
});
171164

172165
it('successfully creates a BlockVolume when AABB extents coords are 0.5', () => {
173166
const aabb: AABB = { center: VECTOR3_ZERO, extents: { x: 0.5, y: 0.5, z: 0.5 } };
174167
const blockVolume = AABBUtils.getBlockVolume(aabb);
175-
expectVector3({ x: -1.0, y: -1.0, z: -1.0 }, blockVolume.from).toBe(true);
176-
expectVector3({ x: 1.0, y: 1.0, z: 1.0 }, blockVolume.to).toBe(true);
168+
expect(blockVolume.from).toEqual({ x: -1.0, y: -1.0, z: -1.0 });
169+
expect(blockVolume.to).toEqual({ x: 1.0, y: 1.0, z: 1.0 });
177170
});
178171

179172
it('successfully creates a BlockVolume when AABB center and extent coords are 0.5', () => {
180173
const aabb: AABB = { center: { x: 0.5, y: 0.5, z: 0.5 }, extents: { x: 0.5, y: 0.5, z: 0.5 } };
181174
const blockVolume = AABBUtils.getBlockVolume(aabb);
182-
expectVector3({ x: 0.0, y: 0.0, z: 0.0 }, blockVolume.from).toBe(true);
183-
expectVector3({ x: 1.0, y: 1.0, z: 1.0 }, blockVolume.to).toBe(true);
175+
expect(blockVolume.from).toEqual({ x: 0.0, y: 0.0, z: 0.0 });
176+
expect(blockVolume.to).toEqual({ x: 1.0, y: 1.0, z: 1.0 });
184177
});
185178

186179
it('successfully creates a BlockVolume when AABB center coords are -0.5 and extent coords are 0.5', () => {
187180
const aabb: AABB = { center: { x: -0.5, y: -0.5, z: -0.5 }, extents: { x: 0.5, y: 0.5, z: 0.5 } };
188181
const blockVolume = AABBUtils.getBlockVolume(aabb);
189-
expectVector3({ x: -1.0, y: -1.0, z: -1.0 }, blockVolume.from).toBe(true);
190-
expectVector3({ x: 0.0, y: 0.0, z: 0.0 }, blockVolume.to).toBe(true);
182+
expect(blockVolume.from).toEqual({ x: -1.0, y: -1.0, z: -1.0 });
183+
expect(blockVolume.to).toEqual({ x: -0.0, y: -0.0, z: -0.0 });
191184
});
192185

193186
it('successfully creates a BlockVolume when AABB extents are greater than VECTOR3_ZERO within epsilon', () => {
194187
const aabb: AABB = { center: VECTOR3_ZERO, extents: { x: 0.00001, y: 0.00001, z: 0.00001 } };
195188
const blockVolume = AABBUtils.getBlockVolume(aabb);
196-
expectVector3({ x: 0.0, y: 0.0, z: 0.0 }, blockVolume.from).toBe(true);
197-
expectVector3({ x: 0.0, y: 0.0, z: 0.0 }, blockVolume.to).toBe(true);
189+
expect(blockVolume.from).toEqual({ x: 0.0, y: 0.0, z: 0.0 });
190+
expect(blockVolume.to).toEqual({ x: 0.0, y: 0.0, z: 0.0 });
198191
});
199192

200193
it('successfully creates a BlockVolume when AABB extents are greater than VECTOR3_ZERO exceeding epsilon', () => {
201194
const aabb: AABB = { center: VECTOR3_ZERO, extents: { x: 0.00002, y: 0.00002, z: 0.00002 } };
202195
const blockVolume = AABBUtils.getBlockVolume(aabb);
203-
expectVector3({ x: -1.0, y: -1.0, z: -1.0 }, blockVolume.from).toBe(true);
204-
expectVector3({ x: 1.0, y: 1.0, z: 1.0 }, blockVolume.to).toBe(true);
196+
expect(blockVolume.from).toEqual({ x: -1.0, y: -1.0, z: -1.0 });
197+
expect(blockVolume.to).toEqual({ x: 1.0, y: 1.0, z: 1.0 });
205198
});
206199
});

libraries/math/src/vector3/coreHelpers.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ describe('Vector3 operations', () => {
8888
expect(Vector3Utils.floor(input)).toEqual(expected);
8989
});
9090

91+
it('computes the ceil of the vector', () => {
92+
const input: Vector3 = { x: 0.33, y: 1.14, z: 2.55 };
93+
const expected: Vector3 = { x: 1, y: 2, z: 3 };
94+
expect(Vector3Utils.ceil(input)).toEqual(expected);
95+
});
96+
97+
it('computes the ceil of negative vectors', () => {
98+
const input: Vector3 = { x: -0.33, y: -1.14, z: -2.55 };
99+
const expected: Vector3 = { x: -0, y: -1, z: -2 };
100+
expect(Vector3Utils.ceil(input)).toEqual(expected);
101+
});
102+
91103
it('normalizes the vector', () => {
92104
const result: Vector3 = Vector3Utils.normalize(v1);
93105
expect(result.x).toBeCloseTo(0.27, 2);

0 commit comments

Comments
 (0)