func furthestColor()

in SAM2-Demo/Common/Color+Extension.swift [44:57]


func furthestColor(from existingColors: [Color], among candidateColors: [Color]) -> Color {
    var maxMinDistance: Double = 0
    var furthestColor: Color = SAMSegmentation.randomCandidateColor() ?? SAMSegmentation.defaultColor

    for candidate in candidateColors {
        let minDistance = existingColors.map { colorDistance(candidate, $0) }.min() ?? 0
        if minDistance > maxMinDistance {
            maxMinDistance = minDistance
            furthestColor = candidate
        }
    }

    return furthestColor
}