Add scan settings and sensitivity thresholds

This commit is contained in:
2026-07-27 15:40:54 +00:00
parent 2a21f7131d
commit 21496fe852
@@ -0,0 +1,90 @@
import Foundation
/// 類似判定の厳しさ。UI の3段階と検出パラメータを結び付ける。
enum Sensitivity: String, CaseIterable, Identifiable, Sendable {
case strict
case standard
case loose
var id: String { rawValue }
var label: String {
switch self {
case .strict: return "厳しい"
case .standard: return "標準"
case .loose: return "ゆるい"
}
}
var help: String {
switch self {
case .strict: return "コピーやリサイズなど、ほぼ同じ写真だけを検出します"
case .standard: return "リサイズ・再圧縮された同じ写真と、連写の近いカットを検出します"
case .loose: return "トリミングされた版や、似た構図の別カットも検出します"
}
}
/// Vision の feature print 距離のしきい値。これ未満なら「似ている」。
///
/// 実写画像で計測した距離の目安(`docs/calibration.md` 参照):
/// 再エンコード 0.00 / 50%縮小 0.05 / 低画質 0.12 / 25%縮小 0.16 /
/// 連写 0.01 / 同一シーンの別カット 0.02〜0.04 / トリミング 0.42〜0.48 /
/// 無関係な写真 1.38 以上。
var featurePrintThreshold: Double {
switch self {
case .strict: return 0.20 // 25%まで縮小された版までを拾う
case .standard: return 0.30 // 縮小・再圧縮・連写まで。トリミングは拾わない
case .loose: return 0.55 // トリミング版まで拾う。無関係な写真とはなお十分離れている
}
}
/// dHash のハミング距離のしきい値。ここを通ったペアだけ feature print で精査する。
///
/// 同じ計測でのハミング距離: 縮小・低画質 1〜5 / トリミング 9〜17 / 無関係 22〜27。
var hammingThreshold: Int {
switch self {
case .strict: return 8
case .standard: return 12
case .loose: return 20
}
}
}
struct ScanSettings: Equatable, Sendable {
var includesSubfolders = true
var sensitivity: Sensitivity = .standard
}
/// スキャンの進捗。UI にそのまま表示する。
struct ScanProgress: Equatable, Sendable {
enum Phase: Equatable, Sendable {
case scanning
case hashing
case fingerprinting
case comparing
case grouping
var label: String {
switch self {
case .scanning: return "フォルダを走査中"
case .hashing: return "重複を判定中"
case .fingerprinting: return "画像の特徴を計算中"
case .comparing: return "類似度を比較中"
case .grouping: return "グループにまとめ中"
}
}
}
var phase: Phase
var completed: Int = 0
var total: Int = 0
var fractionCompleted: Double? {
guard total > 0 else { return nil }
return min(1, Double(completed) / Double(total))
}
var detailText: String {
total > 0 ? "\(completed) / \(total)" : ""
}
}