Build-Fix: KitColor statt RGBColor (Namenskonflikt mit QuickDraw), öffentlicher JerseySuggestion-Init, k-means vereinfacht, CGFloat→Double; Warnungen (NSLock in async, Captures)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
1 parent
9dcef7bd88
commit
3aa5bdef0e
6 files changed
+72
-40
No files matched your search
@@ -1,12 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
/// Simple RGB color (0…1), Codable for settings.
|
||||
public struct RGBColor: Codable, Hashable, Sendable {
|
||||
public struct KitColor: Codable, Hashable, Sendable {
|
||||
public var r: Double, g: Double, b: Double
|
||||
public init(r: Double, g: Double, b: Double) { self.r = r; self.g = g; self.b = b }
|
||||
|
||||
/// Perceptual-ish distance (weighted RGB, "redmean"), 0 … ~1.
|
||||
public func distance(to o: RGBColor) -> Double {
|
||||
public func distance(to o: KitColor) -> Double {
|
||||
let rm = (r + o.r) / 2
|
||||
let dr = r - o.r, dg = g - o.g, db = b - o.b
|
||||
return sqrt((2 + rm) * dr * dr + 4 * dg * dg + (3 - rm) * db * db) / 3
|
||||
@@ -20,10 +20,10 @@ public struct JerseyTeam: Codable, Hashable, Identifiable, Sendable {
|
||||
public var codeSetID: UUID?
|
||||
/// Code = prefix + number, e.g. "w" + "10" → "w10"
|
||||
public var prefix: String
|
||||
public var shirtColor: RGBColor
|
||||
public var shortsColor: RGBColor?
|
||||
public var shirtColor: KitColor
|
||||
public var shortsColor: KitColor?
|
||||
|
||||
public init(name: String, codeSetID: UUID? = nil, prefix: String, shirtColor: RGBColor, shortsColor: RGBColor? = nil) {
|
||||
public init(name: String, codeSetID: UUID? = nil, prefix: String, shirtColor: KitColor, shortsColor: KitColor? = nil) {
|
||||
self.name = name; self.codeSetID = codeSetID; self.prefix = prefix
|
||||
self.shirtColor = shirtColor; self.shortsColor = shortsColor
|
||||
}
|
||||
@@ -44,6 +44,12 @@ public struct JerseySuggestion: Codable, Hashable, Identifiable, Sendable {
|
||||
public var box: [Double] // x, y, w, h
|
||||
/// Person size in the frame (main subject first)
|
||||
public var personArea: Double
|
||||
|
||||
public init(number: Int, teamID: UUID?, code: String?, replacement: String?, confidence: Double,
|
||||
regions: [JerseyRegion], box: [Double], personArea: Double) {
|
||||
self.number = number; self.teamID = teamID; self.code = code; self.replacement = replacement
|
||||
self.confidence = confidence; self.regions = regions; self.box = box; self.personArea = personArea
|
||||
}
|
||||
}
|
||||
|
||||
public enum JerseyLogic {
|
||||
@@ -72,7 +78,7 @@ public enum JerseyLogic {
|
||||
}
|
||||
|
||||
/// Team whose kit color is closest (shirt for shirt numbers, shorts or shirt for shorts numbers).
|
||||
public static func matchTeam(color: RGBColor, region: JerseyRegion, teams: [JerseyTeam], threshold: Double = 0.30) -> JerseyTeam? {
|
||||
public static func matchTeam(color: KitColor, region: JerseyRegion, teams: [JerseyTeam], threshold: Double = 0.30) -> JerseyTeam? {
|
||||
var best: (JerseyTeam, Double)?
|
||||
for t in teams {
|
||||
var d = color.distance(to: t.shirtColor)
|
||||
|
||||
@@ -161,19 +161,29 @@ public final class ImmichClient: @unchecked Sendable {
|
||||
|
||||
/// Finds or creates an album and returns its id.
|
||||
public func albumId(named name: String) async throws -> String {
|
||||
lock.lock(); let cached = albumCache[name]; lock.unlock()
|
||||
if let cached { return cached }
|
||||
if let cached = cachedAlbum(name) { return cached }
|
||||
if let list = try await send(try request("albums")) as? [[String: Any]],
|
||||
let existing = list.first(where: { ($0["albumName"] as? String) == name }), let id = existing["id"] as? String {
|
||||
lock.lock(); albumCache[name] = id; lock.unlock()
|
||||
cacheAlbum(name, id)
|
||||
return id
|
||||
}
|
||||
guard let created = try await send(try request("albums", method: "POST", json: ["albumName": name])) as? [String: Any],
|
||||
let id = created["id"] as? String else { throw ImmichError.decoding }
|
||||
lock.lock(); albumCache[name] = id; lock.unlock()
|
||||
cacheAlbum(name, id)
|
||||
return id
|
||||
}
|
||||
|
||||
// NSLock must not be used directly in async functions → small synchronous helpers.
|
||||
private func cachedAlbum(_ name: String) -> String? {
|
||||
lock.lock(); defer { lock.unlock() }
|
||||
return albumCache[name]
|
||||
}
|
||||
|
||||
private func cacheAlbum(_ name: String, _ id: String) {
|
||||
lock.lock(); defer { lock.unlock() }
|
||||
albumCache[name] = id
|
||||
}
|
||||
|
||||
public func add(assetIds: [String], toAlbum albumId: String) async throws {
|
||||
_ = try await send(try request("albums/\(albumId)/assets", method: "PUT", json: ["ids": assetIds]))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user