PulseCanvas / app · pulsecanvas.ai / scripts / OriginalGeometrySmoke.swift
| 1 | import Foundation |
| 2 | import simd |
| 3 | |
| 4 | @main struct OriginalGeometrySmoke { |
| 5 | static func matches(_ first: OriginalGeometry.Mesh, _ second: OriginalGeometry.Mesh) -> Bool { |
| 6 | first.indices == second.indices && first.vertices.count == second.vertices.count && zip(first.vertices, second.vertices).allSatisfy { |
| 7 | $0.position == $1.position && $0.color == $1.color && $0.uv == $1.uv |
| 8 | } |
| 9 | } |
| 10 | static func main() { |
| 11 | precondition(OriginalGeometry.Scene.allCases.count == 7) |
| 12 | precondition(OriginalGeometry.sceneNames.count == 7) |
| 13 | let silence = [Float](repeating: 0, count: 32) |
| 14 | let loud = [Float](repeating: 0.85, count: 32) |
| 15 | let bass = (0..<32).map { $0 < 5 ? Float(0.9) : Float(0) } |
| 16 | let treble = (0..<32).map { $0 >= 27 ? Float(0.9) : Float(0) } |
| 17 | var counts: Set<Int> = [] |
| 18 | for scene in OriginalGeometry.Scene.allCases { |
| 19 | let quiet = OriginalGeometry.make(scene: scene.rawValue, time: 1.25, spectrum: silence) |
| 20 | let active = OriginalGeometry.make(scene: scene.rawValue, time: 1.25, spectrum: loud) |
| 21 | let repeatFrame = OriginalGeometry.make(scene: scene.rawValue, time: 1.25, spectrum: loud) |
| 22 | let later = OriginalGeometry.make(scene: scene.rawValue, time: 2.75, spectrum: loud) |
| 23 | let low = OriginalGeometry.make(scene: scene.rawValue, time: 1.25, spectrum: bass) |
| 24 | let high = OriginalGeometry.make(scene: scene.rawValue, time: 1.25, spectrum: treble) |
| 25 | precondition(active.vertices.count > 1000 && active.vertices.count < 20000) |
| 26 | precondition(matches(active, repeatFrame), "Timestamp generation must be deterministic") |
| 27 | precondition(!matches(active, later), "Animation must advance") |
| 28 | precondition(zip(quiet.vertices, active.vertices).contains { $0.position != $1.position }, "Audio must move geometry") |
| 29 | precondition(zip(quiet.vertices, active.vertices).contains { $0.color != $1.color }, "Audio must affect color") |
| 30 | precondition(zip(low.vertices, high.vertices).contains { $0.position != $1.position }, "Band distribution must affect geometry") |
| 31 | for vertex in active.vertices { |
| 32 | precondition((0..<3).allSatisfy { vertex.position[$0].isFinite && abs(vertex.position[$0]) < 30 }) |
| 33 | precondition((0..<4).allSatisfy { vertex.color[$0].isFinite && vertex.color[$0] >= 0 && vertex.color[$0] <= 1 }) |
| 34 | } |
| 35 | precondition(active.indices.allSatisfy { Int($0) < active.vertices.count }) |
| 36 | switch active.primitive { |
| 37 | case .points: precondition(active.indices.isEmpty) |
| 38 | case .triangles: precondition(!active.indices.isEmpty && active.indices.count.isMultiple(of: 3)) |
| 39 | } |
| 40 | let invalid = OriginalGeometry.make(scene: scene.rawValue, time: .infinity, spectrum: [.nan, -.infinity, .infinity], intensity: .nan) |
| 41 | precondition(invalid.vertices.allSatisfy { $0.position.x.isFinite && $0.position.y.isFinite && $0.position.z.isFinite }) |
| 42 | // Tubular and rosette seams must remain closed under uneven spectra. |
| 43 | if scene == .orbitalRings { |
| 44 | for ring in 0..<7 { |
| 45 | let start = ring * 145 * 9 |
| 46 | for edge in 0...8 { precondition(simd_length(low.vertices[start + edge].position - low.vertices[start + 144 * 9 + edge].position) < 0.0001) } |
| 47 | } |
| 48 | } |
| 49 | if scene == .audioMandala { |
| 50 | for ring in 0..<11 { |
| 51 | for side in 0...1 { |
| 52 | let start = ring * 193 * 2 + side * 193 |
| 53 | precondition(simd_length(low.vertices[start].position - low.vertices[start + 192].position) < 0.0001) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | counts.insert(active.vertices.count) |
| 58 | print("PASS: \(scene.title), \(active.vertices.count) vertices, \(active.indices.count / 3) triangles") |
| 59 | } |
| 60 | precondition(counts.count >= 6) |
| 61 | precondition(OriginalGeometry.make(scene: -1, time: 0, spectrum: []).vertices.isEmpty) |
| 62 | print("PASS: seven deterministic designs, finite geometry, valid topology, audio position/color response, frequency distribution and timeline animation") |
| 63 | } |
| 64 | } |