@@ -9,6 +9,13 @@ import type { Vector3 } from '@minecraft/server';
99import { VECTOR3_FORWARD , VECTOR3_ONE , VECTOR3_ZERO , Vector3Utils } from '../vector3/coreHelpers.js' ;
1010import { 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+
1219describe ( 'AABB factories' , ( ) => {
1320 it ( 'successfully reports invalid AABB when created from identical corner points' , ( ) => {
1421 const aabb = AABBUtils . createFromCornerPoints ( VECTOR3_ONE , VECTOR3_ONE ) ;
@@ -158,28 +165,70 @@ describe('AABB BlockVolume operations', () => {
158165 it ( 'successfully creates a BlockVolume when AABB extents are VECTOR3_ONE' , ( ) => {
159166 const aabb : AABB = { center : VECTOR3_ZERO , extents : VECTOR3_ONE } ;
160167 const blockVolume = AABBUtils . getBlockVolume ( aabb ) ;
161- expect ( Vector3Utils . equals ( blockVolume . from , { x : - 1.0 , y : - 1.0 , z : - 1.0 } ) ) . toBe ( true ) ;
162- expect ( Vector3Utils . equals ( blockVolume . to , { x : 1.0 , y : 1.0 , z : 1.0 } ) ) . toBe ( true ) ;
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 ) ;
170+ } ) ;
171+
172+ it ( 'successfully creates a BlockVolume when AABB extents coords are 0.5' , ( ) => {
173+ const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 0.5 , y : 0.5 , z : 0.5 } } ;
174+ 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 ) ;
177+ } ) ;
178+
179+ it ( 'successfully creates a BlockVolume when AABB center and extent coords are 0.5' , ( ) => {
180+ const aabb : AABB = { center : { x : 0.5 , y : 0.5 , z : 0.5 } , extents : { x : 0.5 , y : 0.5 , z : 0.5 } } ;
181+ 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 ) ;
184+ } ) ;
185+
186+ it ( 'successfully creates a BlockVolume when AABB center coords are -0.5 and extent coords are 0.5' , ( ) => {
187+ const aabb : AABB = { center : { x : - 0.5 , y : - 0.5 , z : - 0.5 } , extents : { x : 0.5 , y : 0.5 , z : 0.5 } } ;
188+ 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 ) ;
163191 } ) ;
164192
165- it ( 'successfully creates a BlockVolume when AABB extents are close but less than VECTOR3_ONE' , ( ) => {
193+ it ( 'successfully creates a BlockVolume when AABB extents are less than VECTOR3_ONE within epsilon ' , ( ) => {
166194 const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 0.99999 , y : 0.99999 , z : 0.99999 } } ;
167195 const blockVolume = AABBUtils . getBlockVolume ( aabb ) ;
168- expect ( Vector3Utils . equals ( blockVolume . from , { x : - 1.0 , y : - 1.0 , z : - 1.0 } ) ) . toBe ( true ) ;
169- expect ( Vector3Utils . equals ( blockVolume . to , { x : 1.0 , y : 1.0 , z : 1.0 } ) ) . toBe ( true ) ;
196+ expectVector3 ( { x : - 1.0 , y : - 1.0 , z : - 1.0 } , blockVolume . from ) . toBe ( true ) ;
197+ expectVector3 ( { x : 1.0 , y : 1.0 , z : 1.0 } , blockVolume . to ) . toBe ( true ) ;
170198 } ) ;
171199
172- it ( 'successfully creates a BlockVolume when AABB extents are close but greater than VECTOR3_ZERO' , ( ) => {
200+ it ( 'successfully creates a BlockVolume when AABB extents are less than VECTOR3_ONE exceeding epsilon' , ( ) => {
201+ const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 0.99998 , y : 0.99998 , z : 0.99998 } } ;
202+ 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 ) ;
205+ } ) ;
206+
207+ it ( 'successfully creates a BlockVolume when AABB extents are greater than VECTOR3_ZERO within epsilon' , ( ) => {
173208 const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 0.00001 , y : 0.00001 , z : 0.00001 } } ;
174209 const blockVolume = AABBUtils . getBlockVolume ( aabb ) ;
175- expect ( Vector3Utils . equals ( blockVolume . from , { x : - 1 .0, y : - 1 .0, z : - 1 .0 } ) ) . toBe ( true ) ;
176- expect ( Vector3Utils . equals ( blockVolume . to , { x : 1 .0, y : 1 .0, z : 1 .0 } ) ) . toBe ( true ) ;
210+ expectVector3 ( { x : 0 .0, y : 0 .0, z : 0 .0 } , blockVolume . from ) . toBe ( true ) ;
211+ expectVector3 ( { x : 0 .0, y : 0 .0, z : 0 .0 } , blockVolume . to ) . toBe ( true ) ;
177212 } ) ;
178213
179- it ( 'successfully creates a BlockVolume when AABB extents are close but greater than VECTOR3_ONE' , ( ) => {
214+ it ( 'successfully creates a BlockVolume when AABB extents are greater than VECTOR3_ZERO exceeding epsilon' , ( ) => {
215+ const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 0.00002 , y : 0.00002 , z : 0.00002 } } ;
216+ const blockVolume = AABBUtils . getBlockVolume ( aabb ) ;
217+ expectVector3 ( { x : - 1.0 , y : - 1.0 , z : - 1.0 } , blockVolume . from ) . toBe ( true ) ;
218+ expectVector3 ( { x : 1.0 , y : 1.0 , z : 1.0 } , blockVolume . to ) . toBe ( true ) ;
219+ } ) ;
220+
221+ it ( 'successfully creates a BlockVolume when AABB extents are greater than VECTOR3_ONE within epsilon' , ( ) => {
180222 const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 1.00001 , y : 1.00001 , z : 1.00001 } } ;
181223 const blockVolume = AABBUtils . getBlockVolume ( aabb ) ;
182- expect ( Vector3Utils . equals ( blockVolume . from , { x : - 2.0 , y : - 2.0 , z : - 2.0 } ) ) . toBe ( true ) ;
183- expect ( Vector3Utils . equals ( blockVolume . to , { x : 2.0 , y : 2.0 , z : 2.0 } ) ) . toBe ( true ) ;
224+ expectVector3 ( { x : - 1.0 , y : - 1.0 , z : - 1.0 } , blockVolume . from ) . toBe ( true ) ;
225+ expectVector3 ( { x : 1.0 , y : 1.0 , z : 1.0 } , blockVolume . to ) . toBe ( true ) ;
226+ } ) ;
227+
228+ it ( 'successfully creates a BlockVolume when AABB extents are greater than VECTOR3_ONE exceeding epsilon' , ( ) => {
229+ const aabb : AABB = { center : VECTOR3_ZERO , extents : { x : 1.00002 , y : 1.00002 , z : 1.00002 } } ;
230+ const blockVolume = AABBUtils . getBlockVolume ( aabb ) ;
231+ expectVector3 ( { x : - 2.0 , y : - 2.0 , z : - 2.0 } , blockVolume . from ) . toBe ( true ) ;
232+ expectVector3 ( { x : 2.0 , y : 2.0 , z : 2.0 } , blockVolume . to ) . toBe ( true ) ;
184233 } ) ;
185234} ) ;
0 commit comments