Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Valo-Plex iOS9// File : ValoPlex/Design/Facade.swift10// Description : l'élévation de l'immeuble, dessinée d'après le rôle11// (logements, étages, mitoyenneté), la marque (petite façade12// de brique) et la ligne de cote de la fourchette. Même13// géométrie que src/components/Facade.tsx et Cote.tsx du14// site.15// Module : ValoPlex16// Repository : https://git.spboucher.ai/valo-plex-ios17// Project Website : https://www.valo-plex.com18// Created : 2026-12-0119// Last Modified : 2026-12-0120//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author : Simon-Pierre Boucher26// Position : Professor of Finance27// Institution : Université du Québec en Outaouais (UQO)28// Department : Département des sciences administratives29// Organization : SP Boucher30//31// Website : https://spboucher.ai32// Git : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General : info@spboucher.ai39// Professional : contact@spboucher.ai40// Direct : simon@spboucher.ai41// Research : research@spboucher.ai42// Development : dev@spboucher.ai43// Support : support@spboucher.ai44// Security/Admin : admin@spboucher.ai45// Notifications : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification : Public72// Distribution : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License : None specified (no license file in this repository)86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import SwiftUI9495/// Géométrie de l'élévation, séparée du dessin pour être vérifiable.96struct PlanFacade: Equatable {97 let logements: Int98 let niveaux: Int99 let travees: Int100 let mitoyenGauche: Bool101 let mitoyenDroite: Bool102103 static let L: CGFloat = 28104 static let H: CGFloat = 34105106 init(logements: Int, etages: Double? = nil, lien: String? = nil) {107 let n = max(1, logements)108 self.logements = n109 let defaut = n <= 3 ? Double(n) : n <= 8 ? 2 : 3110 let e = (etages ?? 0) > 0 ? etages! : defaut111 niveaux = max(1, min(6, Int(e.rounded())))112 travees = max(2, min(9, Int((Double(n) / Double(niveaux)).rounded(.up)) * 2))113 let l = lien ?? ""114 mitoyenGauche = l == "Jumelé" || l.hasPrefix("En rangée")115 mitoyenDroite = l == "En rangée plus de 1 côté"116 }117118 var largeur: CGFloat { CGFloat(travees) * Self.L + 16 }119 var hauteur: CGFloat { CGFloat(niveaux) * Self.H + 14 }120 var W: CGFloat { max(largeur + 80, 300) }121 var sol: CGFloat { hauteur + 26 }122 var total: CGFloat { sol + 22 }123 var x0: CGFloat { (W - largeur) / 2 }124125 /// Une porte au rez-de-chaussée toutes les quatre travées, à partir de la deuxième.126 func estPorte(niveau: Int, travee: Int) -> Bool { niveau == 0 && travee % 4 == 1 }127128 var description: String {129 "Élévation schématique : \(logements) logements sur \(niveaux) étage\(niveaux > 1 ? "s" : "")"130 }131}132133/// Le geste de la marque (section « mouvement » de globals.css) : le mur se lève du sol, le toit se pose,134/// puis les ouvertures s'éclairent une à une. Durées en millisecondes ; `t` nul = dessin achevé.135enum Geste {136 static let lever = 520.0137 static let toitDepart = 420.0138 static let toitDuree = 300.0139 static let eclairer = 240.0140 /// Marque : dalle, puis fenêtres bas-gauche, haut-gauche, haut-droite, la porte en dernier.141 static let dalleDepart = 380.0142 static let fenetresMarque = [620.0, 740.0, 860.0, 980.0]143 static let dureeMarque = 980.0 + 240.0144 static let ronde = 1200.0145146 /// cubic-bezier(0.2, 0.7, 0.2, 1), approché : départ vif, arrivée douce.147 static func sortie(_ x: Double) -> Double { 1 - pow(1 - borne(x), 3) }148 /// cubic-bezier(0.3, 1.45, 0.5, 1), approché : arrive, dépasse à peine, se pose.149 static func pose(_ x: Double) -> Double {150 let u = borne(x) - 1151 return 1 + 2.2 * u * u * u + 1.2 * u * u152 }153 static func borne(_ x: Double) -> Double { min(1, max(0, x)) }154 /// Avancement de 0 à 1 d'une étape qui part à `depart` et dure `duree`.155 static func etape(_ t: Double?, _ depart: Double, _ duree: Double) -> Double {156 guard let t else { return 1 }157 return borne((t - depart) / duree)158 }159 /// Façade : chaque ouverture s'éclaire du rez-de-chaussée au toit, travée après travée.160 static func retardFenetre(niveau: Int, travee: Int) -> Double { 420 + Double(niveau) * 150 + Double(travee) * 45 }161 static func dureeFacade(_ p: PlanFacade) -> Double { retardFenetre(niveau: p.niveaux - 1, travee: p.travees - 1) + eclairer }162 /// Ronde d'attente : opacité d'une fenêtre, de 1 à 0,15 et retour, décalée de 300 ms par fenêtre.163 static func opaciteRonde(_ t: Double, fenetre: Int) -> Double {164 let phase = ((t - Double(fenetre) * 300).truncatingRemainder(dividingBy: ronde) + ronde).truncatingRemainder(dividingBy: ronde) / ronde165 return 0.15 + 0.85 * (0.5 + 0.5 * cos(2 * .pi * phase))166 }167}168169/// Horloge d'un geste : le temps écoulé depuis l'apparition, en millisecondes ; s'arrête à `duree` (sauf en boucle).170/// Aucun mouvement si l'appareil demande d'en réduire : le dessin arrive achevé.171struct Horloge<Contenu: View>: View {172 let duree: Double173 var boucle = false174 /// Instant imposé (captures et tests) : le dessin est figé à ce temps.175 var fige: Double? = nil176 @ViewBuilder var contenu: (Double?) -> Contenu177178 @State private var debut = Date()179 @State private var fini = false180 @Environment(\.accessibilityReduceMotion) private var sobre181182 var body: some View {183 if let fige {184 contenu(fige)185 } else if sobre || (fini && !boucle) {186 contenu(nil)187 } else {188 TimelineView(.animation) { ligne in189 contenu(ligne.date.timeIntervalSince(debut) * 1000)190 }191 .task {192 guard !boucle else { return }193 try? await Task.sleep(for: .milliseconds(Int(duree) + 60))194 fini = true195 }196 }197 }198}199200struct Facade: View {201 let plan: PlanFacade202 /// La cote « N portes » sous le sol ; retirée sur les vignettes.203 var cote = true204 var fondCote: Color = VX.papier205 /// L'élévation se bâtit à son arrivée : mur, toit, puis les ouvertures une à une.206 var anime = false207 /// Instant imposé du geste, en millisecondes (captures).208 var fige: Double? = nil209210 init(logements: Int, etages: Double? = nil, lien: String? = nil, cote: Bool = true, fondCote: Color = VX.papier, anime: Bool = false, fige: Double? = nil) {211 self.fige = fige212 plan = PlanFacade(logements: logements, etages: etages, lien: lien)213 self.cote = cote214 self.fondCote = fondCote215 self.anime = anime216 }217218 var body: some View {219 let p = plan220 Group {221 if anime || fige != nil {222 Horloge(duree: Geste.dureeFacade(p), fige: fige) { t in dessin(t) }223 } else {224 dessin(nil)225 }226 }227 .aspectRatio(p.W / (cote ? p.total : p.sol + 4), contentMode: .fit)228 .accessibilityElement(children: .ignore)229 .accessibilityLabel(p.description)230 }231232 private func dessin(_ t: Double?) -> some View {233 let p = plan234 return Canvas { ctx, taille in235 let k = taille.width / p.W236 ctx.scaleBy(x: k, y: k)237 let L = PlanFacade.L, H = PlanFacade.H238 let x0 = p.x0, sol = p.sol239 let tirets = StrokeStyle(lineWidth: 1, dash: [3, 3])240 if p.mitoyenGauche {241 ctx.stroke(Path(CGRect(x: x0 - 34, y: sol - p.hauteur + 12, width: 34, height: p.hauteur - 12)), with: .color(VX.trait), style: tirets)242 }243 if p.mitoyenDroite {244 ctx.stroke(Path(CGRect(x: x0 + p.largeur, y: sol - p.hauteur + 12, width: 34, height: p.hauteur - 12)), with: .color(VX.trait), style: tirets)245 }246 // le mur se lève du sol247 let leve = Geste.sortie(Geste.etape(t, 0, Geste.lever))248 let mur = CGRect(x: x0, y: sol - p.hauteur, width: p.largeur, height: p.hauteur)249 var m = ctx250 m.clip(to: Path(CGRect(x: x0 - 4, y: sol + 2 - (p.hauteur + 4) * leve, width: p.largeur + 8, height: (p.hauteur + 4) * leve)))251 m.fill(Path(mur), with: .color(VX.brique))252 m.stroke(Path(mur), with: .color(VX.encre), lineWidth: 1.5)253 for n in 1..<max(1, p.niveaux) {254 var l = Path()255 l.move(to: CGPoint(x: x0, y: sol - CGFloat(n) * H))256 l.addLine(to: CGPoint(x: x0 + p.largeur, y: sol - CGFloat(n) * H))257 m.stroke(l, with: .color(VX.briqueFonce), lineWidth: 1)258 }259 // le toit se pose260 let pose = Geste.etape(t, Geste.toitDepart, Geste.toitDuree)261 if pose > 0 {262 var c = ctx263 c.opacity = Geste.borne(pose * 1.6)264 c.translateBy(x: 0, y: -7 * (1 - Geste.pose(pose)))265 c.fill(Path(CGRect(x: x0 - 4, y: sol - p.hauteur - 6, width: p.largeur + 8, height: 8)), with: .color(VX.encre))266 }267 // les ouvertures s'éclairent une à une268 for n in 0..<p.niveaux {269 for tr in 0..<p.travees {270 let e = Geste.etape(t, Geste.retardFenetre(niveau: n, travee: tr), Geste.eclairer)271 guard e > 0 else { continue }272 let x = x0 + 8 + CGFloat(tr) * L + 6273 let y = sol - CGFloat(n + 1) * H + 8274 let porte = p.estPorte(niveau: n, travee: tr)275 let f = porte ? CGRect(x: x + 1, y: y + 2, width: L - 14, height: H - 10) : CGRect(x: x, y: y, width: L - 12, height: H - 16)276 var c = ctx277 c.opacity = Geste.borne(e * 1.6)278 let echelle = 0.6 + 0.4 * Geste.pose(e)279 c.translateBy(x: f.midX, y: f.midY)280 c.scaleBy(x: echelle, y: echelle)281 c.translateBy(x: -f.midX, y: -f.midY)282 if porte {283 c.fill(Path(f), with: .color(VX.encre))284 } else {285 c.fill(Path(f), with: .color(VX.carton))286 c.stroke(Path(f), with: .color(VX.encre), lineWidth: 1)287 var meneau = Path()288 meneau.move(to: CGPoint(x: f.midX, y: f.minY))289 meneau.addLine(to: CGPoint(x: f.midX, y: f.maxY))290 c.stroke(meneau, with: .color(VX.encre), lineWidth: 0.7)291 }292 }293 }294 var terre = Path()295 terre.move(to: CGPoint(x: 8, y: sol))296 terre.addLine(to: CGPoint(x: p.W - 8, y: sol))297 ctx.stroke(terre, with: .color(VX.encre), lineWidth: 1.5)298 guard cote else { return }299 var c = Path()300 c.move(to: CGPoint(x: x0, y: sol + 12)); c.addLine(to: CGPoint(x: x0 + p.largeur, y: sol + 12))301 c.move(to: CGPoint(x: x0, y: sol + 7)); c.addLine(to: CGPoint(x: x0, y: sol + 17))302 c.move(to: CGPoint(x: x0 + p.largeur, y: sol + 7)); c.addLine(to: CGPoint(x: x0 + p.largeur, y: sol + 17))303 ctx.stroke(c, with: .color(VX.encre2), lineWidth: 0.8)304 let texte = ctx.resolve(Text("\(p.logements) PORTES").font(.custom("IBMPlexMono-Regular", fixedSize: 10)).foregroundStyle(VX.encre2))305 let mesure = texte.measure(in: CGSize(width: 200, height: 40))306 ctx.fill(Path(CGRect(x: p.W / 2 - mesure.width / 2 - 6, y: sol + 5, width: mesure.width + 12, height: 14)), with: .color(fondCote))307 ctx.draw(texte, at: CGPoint(x: p.W / 2, y: sol + 12), anchor: .center)308 }309 }310}311312/// La marque : petite façade de brique à deux niveaux, trois fenêtres et une porte.313/// `anime` : elle se bâtit à son arrivée ; `boucle` : attente réelle, les fenêtres s'éteignent et se rallument en ronde.314struct Marque: View {315 var taille: CGFloat = 28316 var anime = false317 var boucle = false318 var fige: Double? = nil319320 var body: some View {321 Group {322 if anime || boucle || fige != nil {323 Horloge(duree: Geste.dureeMarque, boucle: boucle, fige: fige) { t in dessin(t) }324 } else {325 dessin(nil)326 }327 }328 .frame(width: taille, height: taille)329 .accessibilityHidden(true)330 }331332 private func dessin(_ t: Double?) -> some View {333 Canvas { ctx, dim in334 let k = dim.width / 28335 ctx.scaleBy(x: k, y: k)336 Self.dessiner(&ctx, t: t, boucle: boucle)337 }338 }339340 static let fenetres = [341 CGRect(x: 6.5, y: 17.5, width: 5, height: 5), CGRect(x: 6.5, y: 8, width: 5, height: 5),342 CGRect(x: 16.5, y: 8, width: 5, height: 5), CGRect(x: 17, y: 17.5, width: 4.5, height: 7.5),343 ]344345 static func dessiner(_ ctx: inout GraphicsContext, t: Double? = nil, boucle: Bool = false) {346 let bati: Double? = boucle ? nil : t347 let leve = Geste.sortie(Geste.etape(bati, 0, Geste.lever))348 let mur = CGRect(x: 3, y: 5, width: 22, height: 20)349 var m = ctx350 m.clip(to: Path(CGRect(x: 0, y: 26 - 22 * leve, width: 28, height: 22 * leve)))351 m.fill(Path(mur), with: .color(VX.brique))352 m.stroke(Path(mur), with: .color(VX.encre), lineWidth: 1.5)353 let dalle = Geste.etape(bati, Geste.dalleDepart, 200)354 if dalle > 0 {355 var d = ctx356 d.opacity = dalle357 var l = Path()358 l.move(to: CGPoint(x: 3.75, y: 15)); l.addLine(to: CGPoint(x: 24.25, y: 15))359 d.stroke(l, with: .color(VX.briqueFonce), lineWidth: 1)360 }361 let pose = Geste.etape(bati, Geste.toitDepart, Geste.toitDuree)362 if pose > 0 {363 var c = ctx364 c.opacity = Geste.borne(pose * 1.6)365 c.translateBy(x: 0, y: -7 * (1 - Geste.pose(pose)))366 c.fill(Path(CGRect(x: 1.5, y: 2.5, width: 25, height: 3.5)), with: .color(VX.encre))367 }368 for (i, f) in fenetres.enumerated() {369 let e = Geste.etape(bati, Geste.fenetresMarque[i], Geste.eclairer)370 guard e > 0 else { continue }371 var c = ctx372 c.opacity = boucle ? (t.map { Geste.opaciteRonde($0, fenetre: i) } ?? 1) : Geste.borne(e * 1.6)373 let echelle = 0.6 + 0.4 * Geste.pose(e)374 c.translateBy(x: f.midX, y: f.midY)375 c.scaleBy(x: echelle, y: echelle)376 c.translateBy(x: -f.midX, y: -f.midY)377 if i == 3 {378 c.fill(Path(f), with: .color(VX.encre))379 } else {380 c.fill(Path(f), with: .color(VX.carton))381 c.stroke(Path(f), with: .color(VX.encre), lineWidth: 0.8)382 }383 }384 }385}386387/// Échelle de la ligne de cote : bornes élargies de 18 %, étendues pour contenir le repère.388struct EchelleCote: Equatable {389 let min: Double390 let max: Double391392 init(bas: Double, haut: Double, repere: Double? = nil) {393 let marge = (haut - bas) * 0.18394 var lo = bas - marge, hi = haut + marge395 if let repere, repere.isFinite, repere > 0 {396 lo = Swift.min(lo, repere - marge * 0.5)397 hi = Swift.max(hi, repere + marge * 0.5)398 }399 min = lo400 max = hi > lo ? hi : lo + 1401 }402403 /// Position de 0 à 1 le long de la cote.404 func position(_ v: Double) -> Double { Swift.min(1, Swift.max(0, (v - min) / (max - min))) }405}406407/// Fourchette à 80 %, dessinée comme une ligne de cote ; un repère facultatif (prix demandé).408struct Cote: View {409 let bas: Double410 let valeur: Double411 let haut: Double412 var repere: Double? = nil413 var libelleRepere = "repère"414415 var body: some View {416 let e = EchelleCote(bas: bas, haut: haut, repere: repere)417 Canvas { ctx, t in418 let x: (Double) -> CGFloat = { 20 + CGFloat(e.position($0)) * (t.width - 40) }419 let y: CGFloat = 32420 var c = Path()421 c.move(to: CGPoint(x: x(bas), y: y)); c.addLine(to: CGPoint(x: x(haut), y: y))422 c.move(to: CGPoint(x: x(bas), y: y - 9)); c.addLine(to: CGPoint(x: x(bas), y: y + 9))423 c.move(to: CGPoint(x: x(haut), y: y - 9)); c.addLine(to: CGPoint(x: x(haut), y: y + 9))424 ctx.stroke(c, with: .color(VX.encre), lineWidth: 1.5)425 var losange = Path()426 let xv = x(valeur)427 losange.move(to: CGPoint(x: xv, y: y - 7)); losange.addLine(to: CGPoint(x: xv + 7, y: y))428 losange.addLine(to: CGPoint(x: xv, y: y + 7)); losange.addLine(to: CGPoint(x: xv - 7, y: y))429 losange.closeSubpath()430 ctx.fill(losange, with: .color(VX.brique))431 let police = Font.custom("IBMPlexMono-Regular", fixedSize: 11)432 ctx.draw(Text(Fmt.grand(bas)).font(police).foregroundStyle(VX.encre2), at: CGPoint(x: x(bas), y: y + 22), anchor: .center)433 ctx.draw(Text(Fmt.grand(haut)).font(police).foregroundStyle(VX.encre2), at: CGPoint(x: x(haut), y: y + 22), anchor: .center)434 if let repere, repere.isFinite, repere > 0 {435 let xr = x(repere)436 var r = Path()437 r.move(to: CGPoint(x: xr, y: y - 16)); r.addLine(to: CGPoint(x: xr, y: y + 14))438 ctx.stroke(r, with: .color(VX.cuivre), style: StrokeStyle(lineWidth: 1.5, dash: [3, 2]))439 let ancre: UnitPoint = xr > t.width * 0.72 ? .trailing : xr < t.width * 0.28 ? .leading : .center440 ctx.draw(Text("\(libelleRepere) \(Fmt.grand(repere))").font(police).foregroundStyle(VX.cuivre), at: CGPoint(x: xr, y: 7), anchor: ancre)441 }442 }443 .frame(height: 64)444 .accessibilityElement(children: .ignore)445 .accessibilityLabel("Fourchette : de \(Fmt.grand(bas)) à \(Fmt.grand(haut)), valeur \(Fmt.grand(valeur))" + (repere.map { ", \(libelleRepere) \(Fmt.grand($0))" } ?? ""))446 }447}448