Coconut Data Framework
beta
|
00001 00008 #import "CNAlign.h" 00009 00016 static inline void 00017 CNSetPoint(NSPoint * dst, CGFloat x, CGFloat y) 00018 { 00019 dst->x = x ; dst->y = y ; 00020 } 00021 00029 static inline BOOL 00030 CNIsSamePoint(const NSPoint * a, const NSPoint * b) 00031 { 00032 return (a->x == b->x) && (a->y == b->y) ; 00033 } 00034 00041 static inline void 00042 CNAddPoint(NSPoint * dst, const NSPoint * a, const NSPoint * b) 00043 { 00044 dst->x = a->x + b->x ; 00045 dst->y = a->y + b->y ; 00046 } 00047 00054 static inline void 00055 CNDiffPoint(NSPoint * dst, const NSPoint * a, const NSPoint * b) 00056 { 00057 dst->x = a->x - b->x ; 00058 dst->y = a->y - b->y ; 00059 } 00060 00067 static inline void 00068 CNSetSize(NSSize * dst, CGFloat w, CGFloat h) 00069 { 00070 dst->width = w ; dst->height = h ; 00071 } 00072 00079 static inline BOOL 00080 CNIsZeroSize(const NSSize * src) 00081 { 00082 return (src->width == 0.0 && src->height == 0.0) ; 00083 } 00084 00092 static inline BOOL 00093 CNIsSameSize(const NSSize * a, const NSSize * b) 00094 { 00095 return (a->width == b->width) && (a->height == b->height) ; 00096 } 00097 00106 static inline void 00107 CNSetRect(NSRect * dst, CGFloat x, CGFloat y, CGFloat width, CGFloat height) 00108 { 00109 CNSetPoint(&(dst->origin), x, y) ; 00110 CNSetSize(&(dst->size), width, height) ; 00111 } 00112 00119 static inline void 00120 CNInitRect(NSRect * dst) 00121 { 00122 CNSetRect(dst, 0, 0, 0, 0) ; 00123 } 00124 00132 static inline BOOL 00133 CNIsSameRect(const NSRect * a, const NSRect * b) 00134 { 00135 return CNIsSamePoint(&(a->origin), &(b->origin)) && CNIsSameSize(&(a->size), &(b->size)) ; 00136 } 00137 00149 void 00150 CNUnionRect(NSRect * dst, const NSRect * src0, const NSRect * src1) ; 00151 00158 static inline BOOL 00159 CNIsValidRect(const NSRect * src) 00160 { 00161 CGFloat x = (src->origin).x ; 00162 CGFloat y = (src->origin).y ; 00163 CGFloat w = (src->size).width ; 00164 CGFloat h = (src->size).height ; 00165 return (x>=0.0 && y>=0.0 && w>=0.0 && h>=0.0) ; 00166 } 00167 00175 static inline BOOL 00176 CNIsOverwrapperdRect(const NSRect * a, const NSRect * b) 00177 { 00178 CGFloat al = (a->origin).x ; 00179 CGFloat ar = al + (a->size).width ; 00180 CGFloat bl = (b->origin).x ; 00181 CGFloat br = bl + (b->size).width ; 00182 if(!(br<al || ar<=bl)){ 00183 return TRUE ; 00184 } 00185 CGFloat ab = (a->origin).y ; 00186 CGFloat at = ab + (a->size).height ; 00187 CGFloat bb = (b->origin).y ; 00188 CGFloat bt = bb + (a->size).height ; 00189 if(!(bb<at || ab<=bt)){ 00190 return TRUE ; 00191 } 00192 return FALSE ; 00193 } 00194 00204 void 00205 CNAlignRect(NSRect * dst, CNAlign align, const NSRect * bounds, const NSSize * src) ; 00206 00207 enum { 00209 CNPointXPos = 0, 00211 CNPointYPos = 1, 00213 CNPointZPos = 2 00214 } ; 00215 00217 struct CNPoint2D { 00219 CGFloat vector[CNPointYPos + 1] ; 00220 } ; 00221 00228 static inline void 00229 CNSetPoint2D(struct CNPoint2D * dst, CGFloat x, CGFloat y) 00230 { 00231 dst->vector[CNPointXPos] = x ; 00232 dst->vector[CNPointYPos] = y ; 00233 } 00234 00240 static inline const CGFloat * 00241 CNVectorOfPoint2D(const struct CNPoint2D * src) 00242 { 00243 return src->vector ; 00244 } 00245