SPB Git

Repository Public

BrandSymbol.swift 11.9 KB 270 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Vrai-Prix iOS9// File             : VraiPrix/Design/Brand/BrandSymbol.swift10// Description      : le symbole « Aplomb » dessiné nativement (grille 64 × 6411//                    du système de marque) : gabarit de maison à angles vifs,12//                    fil, plomb outremer dont la pointe vient dans l'ouverture13//                    du sol. Mot-symbole.14// Module           : VraiPrix15// Repository       : https://git.spboucher.ai/vrai-prix-ios-v316// Project Website  : https://www.vrai-prix.com17// Created          : 2026-11-2618// Last Modified    : 2026-11-2619//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author           : Simon-Pierre Boucher25// Position         : Professor of Finance26// Institution      : Université du Québec en Outaouais (UQO)27// Department       : Département des sciences administratives28// Organization     : SP Boucher29//30// Website          : https://spboucher.ai31// Git              : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General          : info@spboucher.ai38// Professional     : contact@spboucher.ai39// Direct           : simon@spboucher.ai40// Research         : research@spboucher.ai41// Development      : dev@spboucher.ai42// Support          : support@spboucher.ai43// Security/Admin   : admin@spboucher.ai44// Notifications    : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification   : Public71// Distribution     : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License          : None specified (no license file in this repository)85// Maintainer       : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import SwiftUI9394enum BrandGeometry {95    /// Gabarit : pignon, murs, sol ouvert de x = 26,5 à 37,5.96    static func house(in r: CGRect) -> Path {97        let s = r.width / 6498        func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: r.minX + x * s, y: r.minY + y * s) }99        var path = Path()100        path.move(to: p(26.5, 56)); path.addLine(to: p(11, 56)); path.addLine(to: p(11, 27)); path.addLine(to: p(32, 8))101        path.addLine(to: p(53, 27)); path.addLine(to: p(53, 56)); path.addLine(to: p(37.5, 56))102        return path103    }104105    /// Variante micro (16 à 24 px) : trait plus gras, plomb sans collet.106    static func houseMicro(in r: CGRect) -> Path {107        let s = r.width / 64108        func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: r.minX + x * s, y: r.minY + y * s) }109        var path = Path()110        path.move(to: p(26, 55.5)); path.addLine(to: p(11.5, 55.5)); path.addLine(to: p(11.5, 27.5)); path.addLine(to: p(32, 9))111        path.addLine(to: p(52.5, 27.5)); path.addLine(to: p(52.5, 55.5)); path.addLine(to: p(38, 55.5))112        return path113    }114115    /// Points du plomb dans son propre repère : largeur 14, hauteur 29,75, origine en haut au centre du collet.116    /// Tracé du symbole : `M29.75 29h4.5v4L39 39.5 32 58.75 25 39.5 29.75 33Z`.117    private static let plumbPoints: [CGPoint] = [118        .init(x: -2.25, y: 0), .init(x: 2.25, y: 0), .init(x: 2.25, y: 4), .init(x: 7, y: 10.5),119        .init(x: 0, y: 29.75), .init(x: -7, y: 10.5), .init(x: -2.25, y: 4),120    ]121    static let plumbAspect: CGFloat = 14 / 29.75122123    /// Le plomb, sa pointe en `tip`, de hauteur `height`, incliné de `angle` autour de `pivot` (nil : vertical).124    static func plumb(tip: CGPoint, height: CGFloat) -> Path {125        let s = height / 29.75126        var path = Path()127        for (i, q) in plumbPoints.enumerated() {128            let pt = CGPoint(x: tip.x + q.x * s, y: tip.y - height + q.y * s)129            if i == 0 { path.move(to: pt) } else { path.addLine(to: pt) }130        }131        path.closeSubpath()132        return path133    }134135    static func plumbMicro(in r: CGRect) -> Path {136        let s = r.width / 64137        func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: r.minX + x * s, y: r.minY + y * s) }138        var path = Path()139        path.move(to: p(28.5, 31)); path.addLine(to: p(35.5, 31)); path.addLine(to: p(40, 39)); path.addLine(to: p(32, 59))140        path.addLine(to: p(24, 39)); path.closeSubpath()141        return path142    }143}144145/// Le symbole. Le plomb peut osciller autour du faîte (`angle`, en degrés) : chargement, états vides, bascule.146struct BrandSymbol: View {147    enum Style {148        /// gabarit charbon (ivoire la nuit), plomb outremer149        case color150        /// une seule couleur151        case mono(Color)152        /// tout ivoire, sur aplat outremer153        case onBrand154    }155156    var style: Style = .color157    var angle: Double = 0158    /// sans sol : états vides (« aucune vente », « adresse introuvable »)159    var noFloor = false160161    var body: some View {162        Canvas { ctx, size in163            let side = min(size.width, size.height)164            let r = CGRect(x: (size.width - side) / 2, y: (size.height - side) / 2, width: side, height: side)165            let s = side / 64166            let micro = side < 26167            let (houseColor, plumbColor): (Color, Color) = switch style {168            case .color: (Theme.house, Theme.plumb)169            case .mono(let c): (c, c)170            case .onBrand: (Theme.ivory, Theme.ivory)171            }172            var house = micro ? BrandGeometry.houseMicro(in: r) : BrandGeometry.house(in: r)173            if noFloor {174                var p = Path()175                func q(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: r.minX + x * s, y: r.minY + y * s) }176                p.move(to: q(11, 58.75)); p.addLine(to: q(11, 27)); p.addLine(to: q(32, 8)); p.addLine(to: q(53, 27)); p.addLine(to: q(53, 58.75))177                house = p178            }179            ctx.stroke(house, with: .color(houseColor), style: StrokeStyle(lineWidth: (micro ? 7 : 5.5) * s, lineCap: .butt, lineJoin: .miter, miterLimit: 8))180            // le pendule : fil et plomb tournent autour du faîte181            var pc = ctx182            let pivot = CGPoint(x: r.minX + 32 * s, y: r.minY + (micro ? 13 : 11.5) * s)183            pc.translateBy(x: pivot.x, y: pivot.y)184            pc.rotate(by: .degrees(angle))185            pc.translateBy(x: -pivot.x, y: -pivot.y)186            var fil = Path()187            fil.move(to: pivot); fil.addLine(to: CGPoint(x: pivot.x, y: r.minY + (micro ? 32 : 30) * s))188            pc.stroke(fil, with: .color(houseColor), lineWidth: (micro ? 3.5 : 1.75) * s)189            let plumb = micro ? BrandGeometry.plumbMicro(in: r)190                : BrandGeometry.plumb(tip: CGPoint(x: r.minX + 32 * s, y: r.minY + 58.75 * s), height: 29.75 * s)191            pc.fill(plumb, with: .color(plumbColor))192        }193        .aspectRatio(1, contentMode: .fit)194        .accessibilityHidden(true)195    }196}197198/// Mot-symbole : « Vrai » couleur du texte, trait d'union fin et atténué, « Prix » en outremer. New York 500.199struct Wordmark: View {200    var size: CGFloat = 22201    var withSymbol = true202203    var body: some View {204        HStack(spacing: size * 0.28) {205            if withSymbol { BrandSymbol().frame(width: size * 1.28, height: size * 1.28) }206            HStack(spacing: size * 0.05) {207                Text("Vrai").foregroundStyle(Theme.ink)208                Rectangle().fill(Theme.ink.opacity(0.45)).frame(width: size * 0.28, height: max(1, size * 0.07)).offset(y: size * 0.04)209                Text("Prix").foregroundStyle(Theme.brand)210            }211            .font(.system(size: size, weight: .medium, design: .serif))212            .tracking(-size * 0.022)213        }214        .accessibilityElement(children: .ignore)215        .accessibilityLabel("Vrai-Prix")216    }217}218219/// Icône de position d'un verdict : le losange à gauche de l'aplomb, sur l'aplomb, à droite (grille 24).220struct VerdictIcon: View {221    let verdict: Verdict222    var body: some View {223        Canvas { ctx, size in224            let s = min(size.width, size.height) / 24225            func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: x * s, y: y * s) }226            var lines = Path()227            if verdict.position == 0 {228                lines.move(to: p(12, 3)); lines.addLine(to: p(12, 7.5)); lines.move(to: p(12, 16.5)); lines.addLine(to: p(12, 21))229            } else {230                lines.move(to: p(12, 3)); lines.addLine(to: p(12, 21))231            }232            lines.move(to: p(3, 20.5)); lines.addLine(to: p(21, 20.5))233            let fg = GraphicsContext.Shading.foreground234            ctx.stroke(lines, with: fg, style: StrokeStyle(lineWidth: 1.7 * s, lineCap: .butt, lineJoin: .miter))235            let cx: CGFloat = verdict.position < 0 ? 6 : (verdict.position > 0 ? 18 : 12)236            var d = Path()237            d.move(to: p(cx, 8.5)); d.addLine(to: p(cx + 3.5, 12)); d.addLine(to: p(cx, 15.5)); d.addLine(to: p(cx - 3.5, 12)); d.closeSubpath()238            ctx.fill(d, with: fg)239        }240        .aspectRatio(1, contentMode: .fit)241        .accessibilityHidden(true)242    }243}244245/// Étiquette de verdict : icône de position, libellé, écart signé. Texte en couleur de verdict sur son fond doux.246struct VerdictTag: View {247    let verdict: Verdict248    var gapPct: Double?249    var large = false250    var short = true251252    var body: some View {253        HStack(spacing: large ? 7 : 5) {254            VerdictIcon(verdict: verdict).frame(width: large ? 18 : 14, height: large ? 18 : 14)255            Text(short ? verdict.shortLabel : verdict.label)256            if let gapPct {257                Text("· " + Fmt.pct(gapPct)).num()258            }259        }260        .font(large ? .subheadline.weight(.semibold) : .caption.weight(.semibold))261        .lineLimit(1).minimumScaleFactor(0.7)262        .foregroundStyle(Theme.color(for: verdict))263        .padding(.horizontal, large ? 10 : 7)264        .padding(.vertical, large ? 6 : 4)265        .background(Theme.softColor(for: verdict), in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))266        .accessibilityElement(children: .ignore)267        .accessibilityLabel(verdict.label + (gapPct.map { ", écart de " + Fmt.pct($0) } ?? ""))268    }269}270
Files main
Menu

Theme