package com.example.studentfaceregistry.face

import com.example.studentfaceregistry.data.Student

/**
 * 人脸识别结果
 */
data class RecognitionResult(
    val student: Student?,
    val distance: Float,
    val cosineSimilarity: Float = 0f,
    val matchType: MatchType = MatchType.NO_MATCH
) {
    /**
     * 是否是匹配状态
     */
    val isMatched: Boolean get() = student != null && matchType == MatchType.MATCH

    /**
     * 匹配置信度（0-1，越大越可信）
     */
    val confidence: Float
        get() {
            if (student == null) return 0f
            // 结合余弦相似度和欧氏距离计算置信度
            // 对于 L2 归一化的 512 维向量，欧氏距离通常在 0-2 之间
            val distanceScore = (1f - (distance / 2f)).coerceIn(0f, 1f)
            return ((cosineSimilarity + 1f) / 2f * 0.6f + distanceScore * 0.4f).coerceIn(0f, 1f)
        }
}
