Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : Groupe Ka — app iOS native7// File : Shared/Courbes.swift8// Module : Utilities9// Repository : https://git.spboucher.ai/groupe-ka-ios10// Project Website : Not specified11// Created : 2026-12-0312// Last Modified : 2026-12-0313//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation4243/// Courbes de mouvement de la famille (mêmes valeurs que `src/gestes.ts` du site).44struct Courbe: Sendable {45 let x1: Double, y1: Double, x2: Double, y2: Double46 let lineaire: Bool4748 init(_ x1: Double, _ y1: Double, _ x2: Double, _ y2: Double) {49 self.x1 = x1; self.y1 = y1; self.x2 = x2; self.y2 = y2; lineaire = false50 }5152 private init() { x1 = 0; y1 = 0; x2 = 1; y2 = 1; lineaire = true }5354 /// cubic-bezier(x1, y1, x2, y2) résolue par dichotomie55 func callAsFunction(_ x: Double) -> Double {56 if x <= 0 { return 0 }57 if x >= 1 { return 1 }58 if lineaire { return x }59 func b(_ t: Double, _ a: Double, _ c: Double) -> Double {60 3 * (1 - t) * (1 - t) * t * a + 3 * (1 - t) * t * t * c + t * t * t61 }62 var lo = 0.0, hi = 1.0, t = x63 for _ in 0..<20 {64 let v = b(t, x1, x2)65 if abs(v - x) < 1e-5 { break }66 if v < x { lo = t } else { hi = t }67 t = (lo + hi) / 268 }69 return b(t, y1, y2)70 }7172 static let lineaire = Courbe()73 /// la rotonde : départ franc, arrivée longue74 static let tourner = Courbe(0.5, 0, 0.2, 1)75 /// ce qui franchit un seuil76 static let seuil = Courbe(0.32, 0.08, 0.14, 1)77 /// ce qui arrive78 static let poser = Courbe(0.2, 0.7, 0.2, 1)79 static let vaEtVient = Courbe(0.45, 0, 0.55, 1)80}81