// The one source of every variation a piece of paper has — split from the// paper's arithmetic (`Theme/PaperMetrics.swift`) because it is a function,// not a constant: the same seed is the same edge in every theme.importFoundation/// Deterministic, smooth, seeded noise — the one source of every variation a/// piece of paper has.////// Not `Hasher` and not `random`: `Hasher` is seeded per launch and a random/// edge would redraw on every layout pass, which is the jitter the owner's rule/// forbids. FNV-1a over the seed's UTF-8 feeds an xorshift stream, which fills a/// small ring of values; reading it at a unit position interpolates the ring/// with a raised cosine, so the edge wanders rather than stepping.publicstructPaperNoise: Sendable {privatelet ring: [Double]/// `count` control points around the ring. More points is a busier edge;/// every caller names its own count, from the theme's scale.publicinit(seed: String, salt: UInt64, count: Int) {var state = SeededNoise.start(PaperNoise.fnv1a(seed), salt: salt)let points = max(SeededNoise.minimumRing, count)var values: [Double] = [] values.reserveCapacity(points)for _ in0..<points { values.append(SeededNoise.advance(&state)) } ring = values }/// The value at `unit` (0…1 walks the ring once), in 0…1.publicfunc value(at unit: Double) -> Double {let count = ring.countlet position = (unit - unit.rounded(.down)) * Double(count)let index = Int(position) % countlet next = (index + 1) % countlet fraction = position - Double(Int(position))// Raised cosine: the curve is flat where two control points meet, so// the edge has no visible kinks.let eased = SeededNoise.eased(fraction)return ring[index] * (1 - eased) + ring[next] * eased }/// One value in 0…1 from a seed and a salt, with no ring at all — for the/// things that vary once per object rather than along an edge.publicstaticfunc unit(seed: String, salt: UInt64) -> Double {var state = SeededNoise.start(fnv1a(seed), salt: salt)returnSeededNoise.advance(&state) }/// FNV-1a over the seed's UTF-8 — the same number on every launch and every/// device, which `Hasher` is not. The caps' hash, reused rather than/// re-derived.publicstaticfunc fnv1a(_ text: String) -> UInt64 { CapColour.fnv1a(text) }}