Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created March 14, 2023 02:37
Show Gist options
  • Save sturdysturge/c6027814821b7f058c83ef9d07219aa7 to your computer and use it in GitHub Desktop.
Save sturdysturge/c6027814821b7f058c83ef9d07219aa7 to your computer and use it in GitHub Desktop.
import CoreGraphics
extension CGFloat {
var degrees: CGFloat {
self * CGFloat(180) / .pi
}
}
extension CGPoint {
init(_ size: CGSize) {
self.init(x: size.width, y: size.height)
}
func angle(to point: CGPoint) -> CGFloat {
CGFloat(atan2f(Float(point.x - x), Float(point.y - y))).degrees
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment