2015-10-01 18:19:52 +02:00
|
|
|
#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;
|
|
|
|
}
|
2016-02-25 01:03:51 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|