@@ -4,9 +4,9 @@ import { MergedProperties } from './properties/merged.js'
4
4
import { computedInheritableProperty } from './properties/index.js'
5
5
import { readReactive } from './utils.js'
6
6
7
- export type WithCameraDistance = { cameraDistance : number ; reversePainterSortStableCache ?: number }
7
+ export type WithReversePainterSortStableCache = { reversePainterSortStableCache ?: number }
8
8
9
- export const cameraDistanceKey = Symbol ( 'camera-distance -key' )
9
+ export const reversePainterSortStableCacheKey = Symbol ( 'reverse-painter-sort-stable-cache -key' )
10
10
export const orderInfoKey = Symbol ( 'order-info-key' )
11
11
12
12
export function reversePainterSortStable ( a : RenderItem , b : RenderItem ) {
@@ -18,8 +18,12 @@ export function reversePainterSortStable(a: RenderItem, b: RenderItem) {
18
18
}
19
19
let az = a . z
20
20
let bz = b . z
21
- const aDistanceRef = ( a . object as any ) [ cameraDistanceKey ] as WithCameraDistance | undefined
22
- const bDistanceRef = ( b . object as any ) [ cameraDistanceKey ] as WithCameraDistance | undefined
21
+ const aDistanceRef = ( a . object as any ) [ reversePainterSortStableCacheKey ] as
22
+ | WithReversePainterSortStableCache
23
+ | undefined
24
+ const bDistanceRef = ( b . object as any ) [ reversePainterSortStableCacheKey ] as
25
+ | WithReversePainterSortStableCache
26
+ | undefined
23
27
if ( aDistanceRef != null ) {
24
28
aDistanceRef . reversePainterSortStableCache ??= az
25
29
az = aDistanceRef . reversePainterSortStableCache
@@ -28,14 +32,11 @@ export function reversePainterSortStable(a: RenderItem, b: RenderItem) {
28
32
bDistanceRef . reversePainterSortStableCache ??= bz
29
33
bz = bDistanceRef . reversePainterSortStableCache
30
34
}
31
- if ( aDistanceRef == null || bDistanceRef == null ) {
32
- //default z comparison
33
- return az !== bz ? bz - az : a . id - b . id
34
- }
35
- if ( aDistanceRef === bDistanceRef ) {
35
+ if ( aDistanceRef != null && aDistanceRef === bDistanceRef ) {
36
36
return compareOrderInfo ( ( a . object as any ) [ orderInfoKey ] . value , ( b . object as any ) [ orderInfoKey ] . value )
37
37
}
38
- return bDistanceRef . cameraDistance - aDistanceRef . cameraDistance
38
+ //default z comparison
39
+ return az !== bz ? bz - az : a . id - b . id
39
40
}
40
41
41
42
//the following order tries to represent the most common element order of the respective element types (e.g. panels are most likely the background element)
@@ -163,10 +164,10 @@ function shallowEqualRecord(r1: Record<string, any> | undefined, r2: Record<stri
163
164
164
165
export function setupRenderOrder < T > (
165
166
result : T ,
166
- rootCameraDistance : WithCameraDistance ,
167
+ rootCameraDistance : WithReversePainterSortStableCache ,
167
168
orderInfo : { value : OrderInfo | undefined } ,
168
169
) : T {
169
- ; ( result as any ) [ cameraDistanceKey ] = rootCameraDistance
170
+ ; ( result as any ) [ reversePainterSortStableCacheKey ] = rootCameraDistance
170
171
; ( result as any ) [ orderInfoKey ] = orderInfo
171
172
return result
172
173
}
0 commit comments