CHGenerator/WebsiteGenerator/Extensions/NSSize+Extensions.swift
Christoph Hagen 80d3c08a93 Update generation
- Move to global objects for files and validation
- Only write changed files
- Check images for changes before scaling
- Simplify code
2022-08-26 17:40:51 +02:00

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
}
}