forked from peter-iakovlev/Telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTGGeometry.m
41 lines (35 loc) · 1.03 KB
/
TGGeometry.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#import "TGGeometry.h"
CGSize TGFitSize(CGSize size, CGSize maxSize)
{
if (size.width < 1.0f)
return CGSizeZero;
if (size.height < 1.0f)
return CGSizeZero;
if (size.width > maxSize.width)
{
size.height = (CGFloat)floor((size.height * maxSize.width / size.width));
size.width = maxSize.width;
}
if (size.height > maxSize.height)
{
size.width = (CGFloat)floor((size.width * maxSize.height / size.height));
size.height = maxSize.height;
}
return size;
}
bool TGOrientationIsSideward(UIImageOrientation orientation, bool *mirrored)
{
if (orientation == UIImageOrientationLeft || orientation == UIImageOrientationRight)
{
if (mirrored != NULL)
*mirrored = false;
return true;
}
else if (orientation == UIImageOrientationLeftMirrored || orientation == UIImageOrientationRightMirrored)
{
if (mirrored != NULL)
*mirrored = true;
return true;
}
return false;
}