Skip to content

Commit fbf00df

Browse files
authored
Tests: Separate EllipsoidRegion bounding box containment tests (#1428)
* Update tests * Update file location
1 parent 513a071 commit fbf00df

1 file changed

Lines changed: 52 additions & 36 deletions

File tree

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Vector3, MathUtils, Matrix4, Box3, Sphere } from 'three';
2-
import { EllipsoidRegion } from '../src/three/renderer/math/EllipsoidRegion.js';
3-
import { WGS84_ELLIPSOID } from '../src/three/renderer/math/GeoConstants.js';
2+
import { EllipsoidRegion } from '../../src/three/renderer/math/EllipsoidRegion.js';
3+
import { WGS84_ELLIPSOID } from '../../src/three/renderer/math/GeoConstants.js';
44

55
describe( 'EllipsoidRegion', () => {
66

@@ -214,15 +214,13 @@ describe( 'EllipsoidRegion', () => {
214214

215215
describe( 'Bounding Boxes', () => {
216216

217-
it( 'should encapsulate randomized points.', () => {
217+
describe( 'should encapsulate randomized points', () => {
218218

219-
const POINT_COUNT = 100;
220-
const REGION_COUNT = 100;
221-
const matrix = new Matrix4();
222-
const invMatrix = new Matrix4();
223-
const box = new Box3();
224-
const sphere = new Sphere();
225-
const point = new Vector3();
219+
const POINT_COUNT = 20;
220+
const REGION_COUNT = 20;
221+
222+
// Generate random regions at module load time
223+
const regions = [];
226224
for ( let i = 0; i < REGION_COUNT; i ++ ) {
227225

228226
const region = new EllipsoidRegion( 1, 1, 1 );
@@ -235,41 +233,59 @@ describe( 'EllipsoidRegion', () => {
235233
region.lonStart = MathUtils.mapLinear( Math.random(), 0, 1, 0.0, 2 * Math.PI );
236234
region.lonEnd = region.lonStart + MathUtils.mapLinear( Math.random(), 0, 1, 0, Math.PI );
237235

238-
region.getBoundingBox( box, matrix );
239-
region.getBoundingSphere( sphere );
240-
invMatrix.copy( matrix ).invert();
236+
regions.push( { region, index: i } );
241237

242-
for ( let p = 0; p < POINT_COUNT; p ++ ) {
238+
}
243239

244-
region.getCartographicToPosition(
245-
MathUtils.mapLinear( Math.random(), 0, 1, region.latStart, region.latEnd ),
246-
MathUtils.mapLinear( Math.random(), 0, 1, region.lonStart, region.lonEnd ),
247-
Math.random() > 0.5 ? region.heightStart : region.heightEnd,
248-
point,
249-
);
240+
// Create a describe block for each region
241+
regions.forEach( ( { region, index } ) => {
250242

243+
describe( `Region ${ index }: lat[${ region.latStart }, ${ region.latEnd }] lon[${ region.lonStart }, ${ region.lonEnd }] height[${ region.heightStart }, ${ region.heightEnd }]`, () => {
251244

252-
expect( sphere.containsPoint( point ) ).toBe( true );
253-
point.applyMatrix4( invMatrix );
254-
// if ( ! box.containsPoint( point ) ) {
245+
const matrix = new Matrix4();
246+
const invMatrix = new Matrix4();
247+
const box = new Box3();
248+
const sphere = new Sphere();
249+
250+
// Calculate bounding volumes once for this region
251+
region.getBoundingBox( box, matrix );
252+
region.getBoundingSphere( sphere );
253+
invMatrix.copy( matrix ).invert();
255254

256-
// console.log( `
257-
// p.position.set( ${ point.x }, ${ point.y }, ${ point.z } );
258-
// er.latStart = ${ region.latStart };
259-
// er.latEnd = ${ region.latEnd };
260-
// er.lonStart = ${ region.lonStart };
261-
// er.lonEnd = ${ region.lonEnd };
262-
// er.heightStart = ${ region.heightStart };
263-
// er.heightEnd = ${ region.heightEnd };
255+
// Generate random points for this region
256+
const points = [];
257+
for ( let p = 0; p < POINT_COUNT; p ++ ) {
264258

265-
// `);
259+
const lat = MathUtils.mapLinear( Math.random(), 0, 1, region.latStart, region.latEnd );
260+
const lon = MathUtils.mapLinear( Math.random(), 0, 1, region.lonStart, region.lonEnd );
261+
const height = Math.random() > 0.5 ? region.heightStart : region.heightEnd;
266262

267-
// }
268-
expect( box.containsPoint( point ) ).toBe( true );
263+
const point = new Vector3();
264+
region.getCartographicToPosition( lat, lon, height, point );
269265

270-
}
266+
points.push( { point, lat, lon, height, index: p } );
271267

272-
}
268+
}
269+
270+
// Create an it block for each point
271+
points.forEach( ( { point, lat, lon, height, index } ) => {
272+
273+
it( `Point ${ index }: lat=${ lat }, lon=${ lon }, height=${ height }`, () => {
274+
275+
// Test sphere containment
276+
expect( sphere.containsPoint( point ) ).toBe( true );
277+
278+
// Test box containment
279+
const transformedPoint = point.clone().applyMatrix4( invMatrix );
280+
expect( box.containsPoint( transformedPoint ) ).toBe( true );
281+
282+
} );
283+
284+
} );
285+
286+
} );
287+
288+
} );
273289

274290
} );
275291

0 commit comments

Comments
 (0)