Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / Onyx2D / O2Geometry.h
blob8ed66bb157e61872933cf5c2adb2ff956507d282
1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
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:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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. */
9 #import <Foundation/Foundation.h>
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
15 #define ONYX2D_EXPORT extern
16 #define ONYX2D_STATIC static
17 #define ONYX2D_STATIC_INLINE static inline
19 typedef float O2Float;
21 typedef NSPoint O2Point;
22 typedef NSSize O2Size;
23 typedef NSRect O2Rect;
25 extern const O2Rect O2RectZero;
26 extern const O2Point O2PointZero;
27 extern const O2Size O2SizeZero;
29 static inline O2Rect O2RectMake(O2Float x, O2Float y, O2Float width, O2Float height) {
30 return NSMakeRect(x, y, width, height);
33 static inline O2Point O2PointMake(O2Float x, O2Float y) {
34 return NSMakePoint(x, y);
37 static inline O2Size O2SizeMake(O2Float x, O2Float y) {
38 O2Size result = {x, y};
39 return result;
42 static inline O2Float O2RectGetMinX(O2Rect rect) {
43 return rect.origin.x;
46 static inline O2Float O2RectGetMaxX(O2Rect rect) {
47 return rect.origin.x + rect.size.width;
50 static inline O2Float O2RectGetMinY(O2Rect rect) {
51 return rect.origin.y;
54 static inline O2Float O2RectGetMaxY(O2Rect rect) {
55 return rect.origin.y + rect.size.height;
58 static inline BOOL O2RectContainsPoint(O2Rect rect, O2Point point) {
59 return (point.x >= NSMinX(rect) && point.x <= NSMaxX(rect)) && (point.y >= NSMinY(rect) && point.y <= NSMaxY(rect));
62 static inline BOOL O2PointEqualToPoint(O2Point a, O2Point b) {
63 return ((a.x == b.x) && (a.y == b.y)) ? YES : NO;
66 static inline O2Rect O2RectIntersection(O2Rect rect0, O2Rect rect1) {
67 // FIX: embed code
68 return NSIntersectionRect(rect0, rect1);
71 static inline O2Rect O2RectIntegral(O2Rect rect) {
72 float minx = floor(rect.origin.x);
73 float miny = floor(rect.origin.y);
74 float maxx = ceil(O2RectGetMaxX(rect));
75 float maxy = ceil(O2RectGetMaxY(rect));
77 rect.origin.x = minx;
78 rect.origin.y = miny;
79 rect.size.width = maxx - minx;
80 rect.size.height = maxy - miny;
82 return rect;
85 #ifdef __cplusplus
87 #endif