import Foundation import CoreGraphics /// Pure schema-diagram operations shared by the UI and XCTest suite. enum DiagramLogic { static func selectedObjects(_ requested: Set, available: [String]) -> Set { requested.intersection(Set(available)) } static func arrangedPositions(_ names: [String]) -> [String: CGPoint] { let countPerRow = max(1, Int(ceil(sqrt(Double(max(1, names.count)))))) var positions: [String: CGPoint] = [:] for (index, name) in names.enumerated() { positions[name] = CGPoint(x: CGFloat(index % countPerRow) * 290 + 30, y: CGFloat(index / countPerRow) * 300 + 30) } return positions } static func translatedPosition(_ origin: CGPoint, translation: CGSize, zoom: CGFloat) -> CGPoint { let scale = max(zoom, 0.1) return CGPoint(x: origin.x + translation.width / scale, y: origin.y + translation.height / scale) } }