1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-02 09:27:55 +01:00
Telegram/Share/TGGeometry.m
2016-02-25 01:03:51 +01:00

42 lines
1.0 KiB
Objective-C

#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;
}