|
189 | 189 | "function insertByDistance(objects, maxCount, object, distance) {", |
190 | 190 | " sortResult.isInserted = false;", |
191 | 191 | " 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--) {", |
194 | 194 | " const other = objects[index];", |
195 | 195 | " const otherDistance = other.__cameraDistance;", |
196 | 196 | " if (distance >= otherDistance) {", |
| 197 | + " insertionIndex = index + 1;", |
197 | 198 | " break;", |
198 | 199 | " }", |
199 | 200 | " }", |
200 | | - " if (index + 1 >= maxCount) {", |
| 201 | + " if (insertionIndex >= maxCount) {", |
201 | 202 | " return sortResult;", |
202 | 203 | " }", |
203 | 204 | " object.__cameraDistance = distance", |
204 | | - " objects.splice(index + 1, 0, object);", |
| 205 | + " objects.splice(insertionIndex, 0, object);", |
205 | 206 | " sortResult.isInserted = true;", |
206 | 207 | " if (objects.length > maxCount) {", |
207 | 208 | " sortResult.removedObject = objects.pop();", |
|
0 commit comments