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
- (CGRect)cropRectForRectSize:(CGSize)rectSize rotation:(float)radians { | |
int quadrant = ((int)floor(radians / (M_PI / 2))) & 3; | |
float sign_alpha = ((quadrant & 1) == 0) ? radians : M_PI - radians; | |
float alpha = fmod((fmod(sign_alpha, M_PI) + M_PI), M_PI); | |
CGSize bb = CGSizeMake(rectSize.width * cos(alpha) + rectSize.height * sin(alpha), rectSize.width * sin(alpha) + rectSize.height * cos(alpha)); | |
float gamma = rectSize.width < rectSize.height ? atan2(bb.width, bb.height) : atan2(bb.height, bb.width); | |
float delta = M_PI - alpha - gamma; | |
float length = rectSize.width < rectSize.height ? rectSize.height : rectSize.width; |