Created
September 25, 2017 10:04
-
-
Save leilee/0a5570b2bdea6a5a7ea72c55cd491a7a to your computer and use it in GitHub Desktop.
Operator overloading for CGGeometry
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
#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