25 lines
498 B
Swift
25 lines
498 B
Swift
import Foundation
|
|
|
|
struct ImageOutput: Hashable {
|
|
|
|
let source: String
|
|
|
|
let width: Int
|
|
|
|
let desiredHeight: Int?
|
|
|
|
var ratio: Float? {
|
|
guard let desiredHeight = desiredHeight else {
|
|
return nil
|
|
}
|
|
return Float(desiredHeight) / Float(width)
|
|
}
|
|
|
|
func hasSimilarRatio(as other: ImageOutput) -> Bool {
|
|
guard let other = other.ratio, let ratio = ratio else {
|
|
return true
|
|
}
|
|
return abs(other - ratio) < 0.1
|
|
}
|
|
}
|