Skip to content

Commit d335777

Browse files
committed
Clearer sorting
1 parent 733a7d4 commit d335777

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

examples/3d-car-coin-hunt/3d-car-coin-hunt.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41954,19 +41954,20 @@
4195441954
"function insertByDistance(objects, maxCount, object, distance) {",
4195541955
" sortResult.isInserted = false;",
4195641956
" sortResult.removedObject = null;",
41957-
" let index = objects.length - 1;",
41958-
" for (; index >= 0; index--) {",
41957+
" let insertionIndex = 0;",
41958+
" for (let index = objects.length - 1; index >= 0; index--) {",
4195941959
" const other = objects[index];",
4196041960
" const otherDistance = other.__cameraDistance;",
4196141961
" if (distance >= otherDistance) {",
41962+
" insertionIndex = index + 1;",
4196241963
" break;",
4196341964
" }",
4196441965
" }",
41965-
" if (index + 1 >= maxCount) {",
41966+
" if (insertionIndex >= maxCount) {",
4196641967
" return sortResult;",
4196741968
" }",
4196841969
" object.__cameraDistance = distance",
41969-
" objects.splice(index + 1, 0, object);",
41970+
" objects.splice(insertionIndex, 0, object);",
4197041971
" sortResult.isInserted = true;",
4197141972
" if (objects.length > maxCount) {",
4197241973
" sortResult.removedObject = objects.pop();",

0 commit comments

Comments
 (0)