Cotton code
124 lines · 4.9 KB · SwiftRaw
// GENERATED by `cotton-gen` from `cotton-core — design/mark.rs` — do not edit by hand.// Run `pnpm gen:design`; `gen:design:check` guards drift in CI.//// 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] = [        Point(x: 234.7, y: 15.9, isKnot: true),        Point(x: 407.7, y: 93.0, isKnot: true),        Point(x: 66.6, y: 93.0, isKnot: true),        Point(x: 93.1, y: 259.1, isKnot: true),        Point(x: 92.9, y: 385.1, isKnot: true),        Point(x: 422.7, y: 442.1, isKnot: true),        Point(x: 64.3, y: 527.9, isKnot: true),        Point(x: 388.2, y: 529.9, isKnot: true),        Point(x: 248.2, y: 611.9, isKnot: true),        Point(x: 0.0, y: 318.3, isKnot: false),        Point(x: 232.7, y: 163.5, isKnot: false),        Point(x: 294.1, y: 497.0, isKnot: false),    ]    public static let threads: [Thread] = [        Thread(from: 0, to: 1),        Thread(from: 0, to: 2),        Thread(from: 0, to: 3),        Thread(from: 2, to: 3),        Thread(from: 2, to: 9),        Thread(from: 3, to: 4),        Thread(from: 3, to: 9),        Thread(from: 3, to: 10),        Thread(from: 1, to: 10),        Thread(from: 4, to: 6),        Thread(from: 4, to: 8),        Thread(from: 4, to: 9),        Thread(from: 4, to: 11),        Thread(from: 5, to: 11),        Thread(from: 5, to: 7),        Thread(from: 6, to: 8),        Thread(from: 6, to: 9),        Thread(from: 7, to: 8),    ]    /// A knot's radius, in the same units as ``points``.    public static let knotRadius: CGFloat = 15.5    /// The thread's stroke width, in the same units as ``points``.    public static let threadWidth: CGFloat = 13.5    /// 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: -6.75, y: 0.40000000000000036, width: 444.95, height: 627.0    )    /// 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)        )    }}