My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /CoreGraphics/CGGeometry.h
05eabdf7a51b vs. d45ae97cbc8d Compare: vs.  Format:
Revision d45ae97cbc8d
Go to: 
Project members, sign in to write a code review
/CoreGraphics/CGGeometry.h   05eabdf7a51b /CoreGraphics/CGGeometry.h   d45ae97cbc8d
1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd 1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
2 2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 4
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 6
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8 8
9 #import <CoreGraphics/CoreGraphicsExport.h> 9 #import <CoreGraphics/CoreGraphicsExport.h>
10 #import <CoreFoundation/CFBase.h> 10 #import <CoreFoundation/CFBase.h>
11 #import <stdbool.h> 11 #import <stdbool.h>
12 12
13 COREGRAPHICS_EXPORT const CGRect CGRectZero; 13 COREGRAPHICS_EXPORT const CGRect CGRectZero;
14 COREGRAPHICS_EXPORT const CGRect CGRectNull; 14 COREGRAPHICS_EXPORT const CGRect CGRectNull;
15 COREGRAPHICS_EXPORT const CGPoint CGPointZero; 15 COREGRAPHICS_EXPORT const CGPoint CGPointZero;
16 COREGRAPHICS_EXPORT const CGSize CGSizeZero; 16 COREGRAPHICS_EXPORT const CGSize CGSizeZero;
17 17
18 static inline CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) { 18 static inline CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) {
19 CGRect result={{x,y},{width,height}}; 19 CGRect result={{x,y},{width,height}};
20 return result; 20 return result;
21 } 21 }
22 22
23 static inline CGPoint CGPointMake(CGFloat x,CGFloat y){ 23 static inline CGPoint CGPointMake(CGFloat x,CGFloat y){
24 CGPoint result={x,y}; 24 CGPoint result={x,y};
25 return result; 25 return result;
26 } 26 }
27 27
28 static inline CGSize CGSizeMake(CGFloat x,CGFloat y){ 28 static inline CGSize CGSizeMake(CGFloat x,CGFloat y){
29 CGSize result={x,y}; 29 CGSize result={x,y};
30 return result; 30 return result;
31 } 31 }
32 32
33 static bool CGSizeEqualToSize(CGSize a, CGSize b) { 33 static bool CGSizeEqualToSize(CGSize a, CGSize b) {
34 return a.width == b.width && a.height == b.height; 34 return a.width == b.width && a.height == b.height;
35 } 35 }
36 36
37 static inline CGFloat CGRectGetMinX(CGRect rect){ 37 static inline CGFloat CGRectGetMinX(CGRect rect){
38 return rect.origin.x; 38 return rect.origin.x;
39 } 39 }
40 40
41 static inline CGFloat CGRectGetMaxX(CGRect rect){ 41 static inline CGFloat CGRectGetMaxX(CGRect rect){
42 return rect.origin.x+rect.size.width; 42 return rect.origin.x+rect.size.width;
43 } 43 }
44 44
45 static inline CGFloat CGRectGetMidX(CGRect rect){ 45 static inline CGFloat CGRectGetMidX(CGRect rect){
46 return CGRectGetMinX(rect) + ((CGRectGetMaxX(rect)-CGRectGetMinX(rect))/2.f); 46 return CGRectGetMinX(rect) + ((CGRectGetMaxX(rect)-CGRectGetMinX(rect))/2.f);
47 } 47 }
48 48
49 static inline CGFloat CGRectGetMinY(CGRect rect){ 49 static inline CGFloat CGRectGetMinY(CGRect rect){
50 return rect.origin.y; 50 return rect.origin.y;
51 } 51 }
52 52
53 static inline CGFloat CGRectGetMaxY(CGRect rect){ 53 static inline CGFloat CGRectGetMaxY(CGRect rect){
54 return rect.origin.y+rect.size.height; 54 return rect.origin.y+rect.size.height;
55 } 55 }
56 56
57 static inline CGFloat CGRectGetMidY(CGRect rect){ 57 static inline CGFloat CGRectGetMidY(CGRect rect){
58 return CGRectGetMinY(rect) + ((CGRectGetMaxY(rect)-CGRectGetMinY(rect))/2.f); 58 return CGRectGetMinY(rect) + ((CGRectGetMaxY(rect)-CGRectGetMinY(rect))/2.f);
59 } 59 }
60 60
61 static inline CGFloat CGRectGetWidth(CGRect rect){ 61 static inline CGFloat CGRectGetWidth(CGRect rect){
62 return rect.size.width; 62 return rect.size.width;
63 } 63 }
64 64
65 static inline CGFloat CGRectGetHeight(CGRect rect){ 65 static inline CGFloat CGRectGetHeight(CGRect rect){
66 return rect.size.height; 66 return rect.size.height;
67 } 67 }
68 68
69 static inline bool CGRectContainsPoint(CGRect rect,CGPoint point) { 69 static inline bool CGRectContainsPoint(CGRect rect,CGPoint point) {
70 return (point.x>=CGRectGetMinX(rect) && point.x<=CGRectGetMaxX(rect)) && (point.y>=CGRectGetMinY(rect) && point.y<=CGRectGetMaxY(rect)); 70 return (point.x>=CGRectGetMinX(rect) && point.x<=CGRectGetMaxX(rect)) && (point.y>=CGRectGetMinY(rect) && point.y<=CGRectGetMaxY(rect));
71 } 71 }
72 72
73 static inline bool CGPointEqualToPoint(CGPoint a,CGPoint b){ 73 static inline bool CGPointEqualToPoint(CGPoint a,CGPoint b){
74 return ((a.x==b.x) && (a.y==b.y))?TRUE:FALSE; 74 return ((a.x==b.x) && (a.y==b.y))?TRUE:FALSE;
75 } 75 }
76 76
77 static inline CGRect CGRectInset(CGRect rect,CGFloat dx,CGFloat dy) { 77 static inline CGRect CGRectInset(CGRect rect,CGFloat dx,CGFloat dy) {
78 rect.origin.x+=dx; 78 rect.origin.x+=dx;
79 rect.origin.y+=dy; 79 rect.origin.y+=dy;
80 rect.size.width-=dx*2; 80 rect.size.width-=dx*2;
81 rect.size.height-=dy*2; 81 rect.size.height-=dy*2;
82 return rect; 82 return rect;
83 } 83 }
84 84
85 static inline CGRect CGRectOffset(CGRect rect,CGFloat dx,CGFloat dy) { 85 static inline CGRect CGRectOffset(CGRect rect,CGFloat dx,CGFloat dy) {
86 rect.origin.x+=dx; 86 rect.origin.x+=dx;
87 rect.origin.y+=dy; 87 rect.origin.y+=dy;
88 return rect; 88 return rect;
89 } 89 }
90
91 static inline CGRect CGRectUnion(CGRect a, CGRect b) {
92 float minX = MIN(CGRectGetMinX(a), CGRectGetMinX(b));
93 float minY = MIN(CGRectGetMinY(a), CGRectGetMinY(b));
94 float maxX = MAX(CGRectGetMaxX(a), CGRectGetMaxX(b));
95 float maxY = MAX(CGRectGetMaxY(a), CGRectGetMaxY(b));
96 return CGRectMake(minX, minY, maxX - minX, maxY - minY);
97 }
98 90
99 static inline bool CGRectIsEmpty(CGRect rect) { 91 static inline bool CGRectIsEmpty(CGRect rect) {
100 return ((rect.size.width==0) && (rect.size.height==0))?TRUE:FALSE; 92 return ((rect.size.width==0) && (rect.size.height==0))?TRUE:FALSE;
101 } 93 }
102 94
103 static inline bool CGRectIntersectsRect(CGRect a, CGRect b) 95 static inline bool CGRectIntersectsRect(CGRect a, CGRect b)
104 { 96 {
105 if(b.origin.x > a.origin.x + a.size.width) 97 if(b.origin.x > a.origin.x + a.size.width)
106 return false; 98 return false;
107 if(b.origin.y > a.origin.y + a.size.height) 99 if(b.origin.y > a.origin.y + a.size.height)
108 return false; 100 return false;
109 if(a.origin.x > b.origin.x + b.size.width) 101 if(a.origin.x > b.origin.x + b.size.width)
110 return false; 102 return false;
111 if(a.origin.y > b.origin.y + b.size.height) 103 if(a.origin.y > b.origin.y + b.size.height)
112 return false; 104 return false;
113 return true; 105 return true;
114 } 106 }
115 107
116 static inline bool CGRectEqualToRect(CGRect a, CGRect b) { 108 static inline bool CGRectEqualToRect(CGRect a, CGRect b) {
117 return CGPointEqualToPoint(a.origin, b.origin) && CGSizeEqualToSize(a.size, b.size); 109 return CGPointEqualToPoint(a.origin, b.origin) && CGSizeEqualToSize(a.size, b.size);
118 } 110 }
119 111
120 static inline bool CGRectIsNull(CGRect rect) { 112 static inline bool CGRectIsNull(CGRect rect) {
121 return CGRectEqualToRect(rect, CGRectNull); 113 return CGRectEqualToRect(rect, CGRectNull);
122 } 114 }
123 115
116 extern CGRect CGRectUnion(CGRect a, CGRect b);
124 extern CGRect CGRectIntersection(CGRect a, CGRect b); 117 extern CGRect CGRectIntersection(CGRect a, CGRect b);
125 extern CGRect CGRectIntegral(CGRect rect); 118 extern CGRect CGRectIntegral(CGRect rect);
126 119
127 static inline bool CGRectContainsRect(CGRect a, CGRect b) 120 static inline bool CGRectContainsRect(CGRect a, CGRect b)
128 { 121 {
129 return (CGRectGetMinX(b) >= CGRectGetMinX(a) && 122 return (CGRectGetMinX(b) >= CGRectGetMinX(a) &&
130 CGRectGetMaxX(b) <= CGRectGetMaxX(a) && 123 CGRectGetMaxX(b) <= CGRectGetMaxX(a) &&
131 CGRectGetMinY(b) >= CGRectGetMinY(a) && 124 CGRectGetMinY(b) >= CGRectGetMinY(a) &&
132 CGRectGetMaxY(b) <= CGRectGetMaxY(a)); 125 CGRectGetMaxY(b) <= CGRectGetMaxY(a));
133 } 126 }
Powered by Google Project Hosting