//! `CottonMark.swift` — the logo's geometry, rendered ONCE for both halves. //! //! One file in `CottonPaper`, which the phone and the Mac half both import, //! because it is the same drawing: the phone paints it on the launch screen and //! the pairing screen, the Mac paints it in the menu bar. Before this existed //! each app had its own hand-authored approximation and the two did not agree //! with each other or with the app icon (2026-09-10); rendering two copies of //! this file was the same risk one package further down. //! //! It carries GEOMETRY and PLACEMENT and no colour at all. That is not an //! accident of scope: the palette guard allows a colour literal in exactly one //! generated file, and the logo does not need one — the phone inks //! it with a role the caller passes and the Mac's menu-bar icon is a macOS //! TEMPLATE image, which is alpha coverage and nothing else. The brand's own //! amber and steel-blue live in `cotton_core::design::mark`, where the server's //! pages and the site's assets read them. use cotton_core::design::mark::{ content_bounds, PointKind, KNOT_RADIUS, POINTS, THREADS, THREAD_WIDTH, }; use crate::swift::generated_header; pub fn render() -> String { let (min_x, min_y, max_x, max_y) = content_bounds(); let points = POINTS .iter() .map(|point| { format!( " Point(x: {:?}, y: {:?}, isKnot: {}),", point.x, point.y, point.kind == PointKind::Knot ) }) .collect::>() .join("\n"); let threads = THREADS .iter() .map(|(from, to)| format!(" Thread(from: {from}, to: {to}),")) .collect::>() .join("\n"); format!( r#"{header} // // THE LOGO IS THE CONSTELLATION-C and never a typographic "C." stand-in // (AGENTS.md → Identity). The phone draws it on the launch screen // (`SplashOverlay`) and on the pairing screen (`ConstellationMark`); the Mac // draws it as the menu-bar item's template image (`ConstellationMarkImage`). // // The numbers are the APP ICON'S OWN geometry, read off // `assets/brand/logo-master.png` and held to it by // `scripts/__tests__/constellation-mark.test.ts` — so what a person sees at // launch is the logo they tapped, not a lookalike. import CoreGraphics /// The logo, as geometry — no colour, and no view. /// /// Colour is the CALLER'S: the phone inks the logo with a palette role it /// chooses, and the Mac's menu-bar icon is a template image, which macOS tints /// itself from the alpha alone. Both apps' palette guards allow a hex in one /// generated file and this is not it. public enum CottonMark {{ /// One point of the logo, in the master art's own pixel grid. public struct Point: Equatable, Sendable {{ public let x: CGFloat public let y: CGFloat /// A french knot is drawn as a disc; a turn is only where the thread /// changes direction. Drawing a disc on a turn adds three dots the icon /// has not got. public let isKnot: Bool }} /// One straight run of thread, by index into ``points``. public struct Thread: Equatable, Sendable {{ public let from: Int public let to: Int }} public static let points: [Point] = [ {points} ] public static let threads: [Thread] = [ {threads} ] /// A knot's radius, in the same units as ``points``. public static let knotRadius: CGFloat = {knot_radius:?} /// The thread's stroke width, in the same units as ``points``. public static let threadWidth: CGFloat = {thread_width:?} /// The INK's own bounding box — every point grown by what is drawn on it. /// /// Fitting by this rather than by the point extents is what keeps the /// apex's round join (it sits on x = 0) from being clipped, and what keeps /// the logo from being letterboxed by an empty margin. public static let contentBounds = CGRect( x: {min_x:?}, y: {min_y:?}, width: {width:?}, height: {height:?} ) /// How the logo maps into `size`: scaled to fit, centred. /// /// `minimumThread` and `minimumKnot` are FLOORS in the destination's own /// units, for the small end — at a 22-point menu bar the thread scales to /// well under a pixel and downsamples to an even grey, which reads as a /// smudge or as nothing at all. A floor thickens what is drawn without /// moving anything. public struct Placement: Equatable, Sendable {{ public let scale: CGFloat public let offsetX: CGFloat public let offsetY: CGFloat public let knotRadius: CGFloat public let threadWidth: CGFloat /// Where `point` lands. public func at(_ point: Point) -> CGPoint {{ CGPoint(x: point.x * scale + offsetX, y: point.y * scale + offsetY) }} }} public static func placement( in size: CGSize, minimumThread: CGFloat = 0, minimumKnot: CGFloat = 0 ) -> Placement {{ let box = contentBounds let scale = min(size.width / box.width, size.height / box.height) return Placement( scale: scale, offsetX: (size.width - box.width * scale) / 2 - box.minX * scale, offsetY: (size.height - box.height * scale) / 2 - box.minY * scale, knotRadius: max(knotRadius * scale, minimumKnot), threadWidth: max(threadWidth * scale, minimumThread) ) }} }} "#, header = generated_header("cotton-core — design/mark.rs"), points = points, threads = threads, knot_radius = KNOT_RADIUS, thread_width = THREAD_WIDTH, min_x = min_x, min_y = min_y, width = max_x - min_x, height = max_y - min_y, ) } #[cfg(test)] #[path = "mark_tests.rs"] mod tests;