mirror of
https://github.com/EmergeTools/Pow.git
synced 2026-03-29 09:35:51 +00:00
Co-authored-by: Robert Böhnke <robb@robb.is> Co-authored-by: Kasper Lahti <kasper@lahti.email>
29 lines
755 B
Swift
29 lines
755 B
Swift
import SwiftUI
|
|
|
|
extension CGSize {
|
|
var area: CGFloat {
|
|
width * height
|
|
}
|
|
|
|
func boundingSize(at angle: Angle) -> CGSize {
|
|
var theta: Double = angle.radians
|
|
|
|
let sizeA: CGSize = CGSize(
|
|
width: abs(width * cos(Double(theta)) + height * sin(Double(theta))),
|
|
height: abs(width * sin(Double(theta)) + height * cos(Double(theta)))
|
|
)
|
|
|
|
theta += .pi / 2
|
|
|
|
let sizeB: CGSize = CGSize(
|
|
width: abs(width * sin(Double(theta)) + height * cos(Double(theta))),
|
|
height: abs(width * cos(Double(theta)) + height * sin(Double(theta)))
|
|
)
|
|
|
|
if sizeA.area > sizeB.area {
|
|
return sizeA
|
|
} else {
|
|
return sizeB
|
|
}
|
|
}
|
|
}
|