Last active
June 16, 2020 15:23
-
-
Save prafullakumar/e4b37ecbe5b848e8a7ccb67b76e516d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension CGRect { | |
/// center of rect | |
var center: CGPoint { | |
return CGPoint(x: self.midX, y: self.midY) | |
} | |
/// if rect is not square take centered square to draw | |
var centeredSquare: CGRect { | |
let width = ceil(min(size.width, size.height)) | |
let height = width | |
let newOrigin = CGPoint(x: origin.x + (size.width - width) / 2, y: origin.y + (size.height - height) / 2) | |
let newSize = CGSize(width: width, height: height) | |
return CGRect(origin: newOrigin, size: newSize) | |
} | |
func flatten() -> (CGFloat, CGFloat, CGFloat, CGFloat) { | |
return (origin.x, origin.y, size.width, size.height) | |
} | |
} | |
extension Angle { | |
static let A180 = Angle(radians: .pi) //180 | |
static let A90 = Angle(radians: .pi/2) //90 | |
static let A270 = Angle(radians: (.pi/2) * 3) //270 | |
static let A360 = Angle(radians: .pi * 2) //360 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment