80d3c08a93
- Move to global objects for files and validation - Only write changed files - Check images for changes before scaling - Simplify code
29 lines
536 B
Swift
29 lines
536 B
Swift
import Foundation
|
|
|
|
extension NSSize {
|
|
|
|
func scaledDown(to desiredWidth: CGFloat) -> NSSize {
|
|
if width == desiredWidth {
|
|
return self
|
|
}
|
|
|
|
if width < desiredWidth {
|
|
// Don't scale larger
|
|
return self
|
|
}
|
|
|
|
let height = height * desiredWidth / width
|
|
return NSSize(width: desiredWidth, height: height)
|
|
}
|
|
}
|
|
|
|
extension NSSize {
|
|
|
|
var ratio: CGFloat {
|
|
guard height != 0 else {
|
|
return 0
|
|
}
|
|
return width / height
|
|
}
|
|
}
|