Skip to content

Commit 6101d0a

Browse files
committed
Clearer sorting
1 parent d8043eb commit 6101d0a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

extensions/reviewed/SpotLight3D.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,20 @@
189189
"function insertByDistance(objects, maxCount, object, distance) {",
190190
" sortResult.isInserted = false;",
191191
" sortResult.removedObject = null;",
192-
" let index = objects.length - 1;",
193-
" for (; index >= 0; index--) {",
192+
" let insertionIndex = 0;",
193+
" for (let index = objects.length - 1; index >= 0; index--) {",
194194
" const other = objects[index];",
195195
" const otherDistance = other.__cameraDistance;",
196196
" if (distance >= otherDistance) {",
197+
" insertionIndex = index + 1;",
197198
" break;",
198199
" }",
199200
" }",
200-
" if (index + 1 >= maxCount) {",
201+
" if (insertionIndex >= maxCount) {",
201202
" return sortResult;",
202203
" }",
203204
" object.__cameraDistance = distance",
204-
" objects.splice(index + 1, 0, object);",
205+
" objects.splice(insertionIndex, 0, object);",
205206
" sortResult.isInserted = true;",
206207
" if (objects.length > maxCount) {",
207208
" sortResult.removedObject = objects.pop();",

0 commit comments

Comments
 (0)