Skip to content

Commit

Permalink
Formatting and improve d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
agargaro committed Jul 9, 2024
1 parent 75ec89e commit 8daed55
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,3 @@ example/dev-bundle
.parcel-cache

*.generated.js

build/**
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ Constructs the bounds tree for the given geometry and produces a new index attri
// Print out warnings encountered during tree construction.
verbose: true,

// If given, the MeshBVH will be computed for the given range on the geometry.
// If not specified, geometry.drawRange is used.
range: { start: number, count: number }
// If given, the MeshBVH will be computed for the given range on the geometry.
// If not specified, geometry.drawRange is used.
range: { start: number, count: number }

}
```
Expand Down
7 changes: 1 addition & 6 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ export interface HitPointInfo {
faceIndex: number;
}

export interface BufferRange {
start: number;
count: number;
}

export interface MeshBVHOptions {
strategy?: SplitStrategy;
maxDepth?: number;
Expand All @@ -33,7 +28,7 @@ export interface MeshBVHOptions {
useSharedArrayBuffer?: boolean;
verbose?: boolean;
onProgress?: ( progress: number ) => void;
range?: BufferRange;
range?: { start: number; count: number };
}

export interface MeshBVHSerializeOptions {
Expand Down
38 changes: 19 additions & 19 deletions test/MeshBVH.options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ describe( 'Options', () => {
//
// we would need four BVH roots: [0, 15], [16, 20], [21, 40], [41, 60].

geometry.addGroup( 0 * 3, (20 - 0 + 1) * 3 );
geometry.addGroup( 16 * 3, (40 - 16 + 1) * 3 );
geometry.addGroup( 41 * 3, (60 - 41 + 1) * 3 );
geometry.addGroup( 0 * 3, ( 20 - 0 + 1 ) * 3 );
geometry.addGroup( 16 * 3, ( 40 - 16 + 1 ) * 3 );
geometry.addGroup( 41 * 3, ( 60 - 41 + 1 ) * 3 );

const options = { range: { start: 10 * 3, count: 45 * 3 } }; // range [10, 55]
const bvh = new MeshBVH( geometry, options );
Expand All @@ -327,15 +327,15 @@ describe( 'Options', () => {

for ( let i = 0, l = bvhCount; i < l; i ++ ) {

start[i] = Infinity;
end[i] = 0;
start[ i ] = Infinity;
end[ i ] = 0;

bvh.traverse( ( depth, isLeaf, box, offset, count ) => {

if ( isLeaf ) {

start[i] = Math.min( start[i], offset );
end[i] = Math.max( end[i], offset + count );
start[ i ] = Math.min( start[ i ], offset );
end[ i ] = Math.max( end[ i ], offset + count );

}

Expand All @@ -345,14 +345,14 @@ describe( 'Options', () => {

// [10, 15], [16, 20], [21, 40], [41, 54]

expect( start[0] ).toBe( 10 );
expect( end[0] ).toBe( 16 );
expect( start[1] ).toBe( 16 );
expect( end[1] ).toBe( 21 );
expect( start[2] ).toBe( 21 );
expect( end[2] ).toBe( 41 );
expect( start[3] ).toBe( 41 );
expect( end[3] ).toBe( 55 );
expect( start[ 0 ] ).toBe( 10 );
expect( end[ 0 ] ).toBe( 16 );
expect( start[ 1 ] ).toBe( 16 );
expect( end[ 1 ] ).toBe( 21 );
expect( start[ 2 ] ).toBe( 21 );
expect( end[ 2 ] ).toBe( 41 );
expect( start[ 3 ] ).toBe( 41 );
expect( end[ 3 ] ).toBe( 55 );

} );

Expand Down Expand Up @@ -380,12 +380,12 @@ describe( 'Options', () => {

it( 'should respect the range option with groups, indirect.', () => {

geometry.addGroup( 0 * 3, (20 - 0 + 1) * 3 );
geometry.addGroup( 16 * 3, (40 - 16 + 1) * 3 );
geometry.addGroup( 41 * 3, (60 - 41 + 1) * 3 );
geometry.addGroup( 0 * 3, ( 20 - 0 + 1 ) * 3 );
geometry.addGroup( 16 * 3, ( 40 - 16 + 1 ) * 3 );
geometry.addGroup( 41 * 3, ( 60 - 41 + 1 ) * 3 );

const options = { indirect: true, range: { start: 10 * 3, count: 45 * 3 } }; // range [10, 55]
const bvh = new MeshBVH( geometry, options );
const bvh = new MeshBVH( geometry, options );
let start = Infinity;
let end = 0;
const bvhCount = bvh._roots.length;
Expand Down

0 comments on commit 8daed55

Please sign in to comment.