import Foundation struct LayoutSizeOracle: Codable { let ids: [UInt32] let initial: [ScreenRect] let mainIndex: Int var mainID: UInt32 { ids[mainIndex] } init(ids: [UInt32], initial: [ScreenRect], layout: String) throws { guard !ids.isEmpty, Set(ids).count == ids.count, ids.count == initial.count, initial.allSatisfy(\.isValid) else { throw RealityError("Size baseline requires distinct owned IDs and valid real frames") } let candidates: [Int] if layout == "accordion" { let largest = initial.map(\.area).max() candidates = initial.indices.filter { initial[$0].area == largest } } else { let leading = initial.min { $0.y == $1.y ? $0.x < $1.x : $0.y < $1.y } candidates = initial.indices.filter { initial[$0].x == leading?.x && initial[$0].y == leading?.y } } guard candidates.count == 1, let mainIndex = candidates.first else { throw RealityError("Size baseline cannot identify one main real window") } self.ids = ids self.initial = initial self.mainIndex = mainIndex } func grew(_ frames: [ScreenRect], visible: ScreenRect) -> Bool { frames.count == initial.count && frames[mainIndex].area > initial[mainIndex].area + 100 && FrameOracle.tiles(frames, visible: visible) } func restored(_ frames: [ScreenRect]) -> Bool { frames.count == initial.count && zip(frames, initial).allSatisfy { $0.matches($1, tolerance: 1) } } }