Skip to content

Instantly share code, notes, and snippets.

@leilee
Created September 25, 2017 10:04
Show Gist options
  • Save leilee/0a5570b2bdea6a5a7ea72c55cd491a7a to your computer and use it in GitHub Desktop.
Save leilee/0a5570b2bdea6a5a7ea72c55cd491a7a to your computer and use it in GitHub Desktop.
Operator overloading for CGGeometry
#pragma once
#import <CoreGraphics/CoreGraphics.h>
#pragma mark - CGSize
CG_INLINE
CGSize operator*(const CGSize& lhs, CGFloat f)
{
return (CGSize){lhs.width * f, lhs.height * f};
}
CG_INLINE
CGSize operator/(const CGSize& lhs, CGFloat f)
{
return (CGSize){lhs.width / f, lhs.height / f};
}
CG_INLINE
CGSize operator-(const CGSize& lhs, const CGSize& rhs)
{
return (CGSize){lhs.width - rhs.width, lhs.height - rhs.height};
}
CG_INLINE
BOOL operator==(const CGSize& lhs, const CGSize& rhs)
{
return CGSizeEqualToSize(lhs, rhs);
}
CG_INLINE
BOOL operator!=(const CGSize& lhs, const CGSize& rhs)
{
return !CGSizeEqualToSize(lhs, rhs);
}
#pragma mark - CGRect
CG_INLINE
BOOL operator==(const CGRect& lhs, const CGRect& rhs)
{
return CGRectEqualToRect(lhs, rhs);
}
CG_INLINE
BOOL operator!=(const CGRect& lhs, const CGRect& rhs)
{
return !CGRectEqualToRect(lhs, rhs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment