CHGenerator/Sources/Generator/Extensions/NSSize+Extensions.swift
2022-09-09 11:18:32 +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
}
}