-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify Loop end condition in BufferGeometry.merge() #15827
Conversation
@@ -822,7 +822,7 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy | |||
|
|||
var attributeSize = attribute2.itemSize; | |||
|
|||
for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) { | |||
for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length && j < attributeArray1.length; i ++, j ++ ) { | |||
|
|||
attributeArray1[ j ] = attributeArray2[ i ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Update: Clean up the comment)
This method seems to expect attributeArray1
size won't be resized.
j
can be bigger than the attributeArray1.length
here but attributeArray1/2
are typed array then attributeArray1[ index ] = value; // index >= attributeArray1.length
has no effect.
I think better to make clear the behavior by clarifying loop end condition. And it'll be efficient in case j
can be bigger than attributeArray1.length
because it can cut off no effect operation .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because assigning to an out-of-bounds index in a typed array has no effect and throws no error, this change has no effect on the method output, and just makes the actual behavior more explicit right? Sounds good to me.
Yes, that's right. Thanks for clarifying. |
Would this be more clear? var attributeOffset = attribute2.itemSize * offset;
var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
attributeArray1[ j ] = attributeArray2[ i ];
} |
/ping @takahirox |
Sorry for the late. Updated. |
Thanks! |
Comment inline.