Skip to content

Commit

Permalink
HasGroupGaps tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agargaro committed Jul 16, 2024
1 parent 938cbea commit 15efb01
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/core/build/geometryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ export function getRootIndexRanges( geo, range ) {

export function hasGroupGaps( geometry, range ) {

if ( geometry.groups.length === 0 ) {

return false;

}

const vertexCount = getTriCount( geometry );
const groups = getRootIndexRanges( geometry, range )
.sort( ( a, b ) => a.offset - b.offset );
Expand Down
50 changes: 49 additions & 1 deletion test/Utils.geometryUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ describe( 'hasGroupGaps', () => {

} );

it( 'should not report if range is "infinite".', () => {

const geometry = new SphereGeometry();
const range = { start: 0, count: Infinity };
expect( hasGroupGaps( geometry, range ) ).toBe( false );

} );

it( 'should not report when range spans the entire vertex buffer while geometry.drawRange does not.', () => {

const geometry = new SphereGeometry();
geometry.setDrawRange( 10, getVertexCount( geometry ) - 11 );
const range = { start: 0, count: getVertexCount( geometry ) };
expect( hasGroupGaps( geometry, range ) ).toBe( false );

} );

it( 'should report when a geometry.drawRange does not span the whole vertex buffer.', () => {

const geometry = new SphereGeometry();
geometry.setDrawRange( 0, getVertexCount( geometry ) - 1, );
expect( hasGroupGaps( geometry ) ).toBe( true );

} );

it( 'should report when a geometry has a group that does not span the whole vertex buffer.', () => {

const geometry = new SphereGeometry();
Expand All @@ -42,6 +67,29 @@ describe( 'hasGroupGaps', () => {

} );

// SHOULD WE ADD NEW TEST WITH RANGE?
it( 'should report when range does not span the whole vertex buffer.', () => {

const geometry = new SphereGeometry();
const range = { start: 0, count: getVertexCount( geometry ) - 1 };
expect( hasGroupGaps( geometry, range ) ).toBe( true );

} );

it( 'should report when range does not span the whole vertex buffer while geometry groups do.', () => {

const geometry = new BoxGeometry();
const range = { start: 0, count: getVertexCount( geometry ) - 1 };
expect( hasGroupGaps( geometry, range ) ).toBe( true );

} );

it( 'should report when a geometry has a group that does not span the whole vertex buffer while range does.', () => {

const geometry = new SphereGeometry();
geometry.addGroup( 0, getVertexCount( geometry ) - 1, 0 );
const range = { start: 0, count: Infinity };
expect( hasGroupGaps( geometry, range ) ).toBe( true );

} );

} );

0 comments on commit 15efb01

Please sign in to comment.