Ariver
2026-08-14 21e9dd7c95e3f58a19a7c7342ff3d6584eb9097e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Foundation
 
public struct SpaceEnumerationRecord: Equatable, Sendable {
    public let id: UInt64
    public let cgsType: Int
    public let displayUUID: String
 
    public init(id: UInt64, cgsType: Int, displayUUID: String) {
        self.id = id
        self.cgsType = cgsType
        self.displayUUID = displayUUID
    }
}
 
public enum SpaceEnumerationPolicy {
    public static let sharedDisplayUUID = "Main"
 
    public static func spaceType(fromCGSType type: Int) -> AlignerSpaceType {
        switch type {
        case 0:
            return .user
        case 4:
            return .fullscreen
        default:
            return .unknown(type)
        }
    }
 
    public static func normalizedDisplays(
        from records: [SpaceEnumerationRecord],
        physicalDisplayUUIDs: Set<String> = []
    ) -> [AlignerDisplay] {
        let grouped = Dictionary(grouping: records) { normalizedDisplayUUID($0.displayUUID) }
 
        return grouped.keys.sorted().compactMap { displayUUID in
            guard let records = grouped[displayUUID], !records.isEmpty else { return nil }
 
            let spaces = records.enumerated().map { offset, record in
                AlignerSpace(
                    id: record.id,
                    type: spaceType(fromCGSType: record.cgsType),
                    displayUUID: displayUUID,
                    index: offset + 1
                )
            }
 
            return AlignerDisplay(
                uuid: displayUUID,
                physical: isPhysicalDisplay(displayUUID, physicalDisplayUUIDs: physicalDisplayUUIDs),
                spaces: spaces
            )
        }
    }
 
    private static func normalizedDisplayUUID(_ displayUUID: String) -> String {
        displayUUID.isEmpty ? sharedDisplayUUID : displayUUID
    }
 
    private static func isPhysicalDisplay(_ displayUUID: String, physicalDisplayUUIDs: Set<String>) -> Bool {
        physicalDisplayUUIDs.isEmpty || physicalDisplayUUIDs.contains(displayUUID)
    }
}