Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / editors / scapp / include / SCGeom.h
blob4b8f5255dc675bc4ecb0f37b1ccddb6ca5559eeb
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #if defined(__APPLE__) && !defined(SC_IPHONE)
22 #import <Carbon/Carbon.h>
23 #endif
24 #ifdef SC_IPHONE
25 #import <UIKit/UIKit.h>
26 #endif
27 #include "SC_BoundsMacros.h"
29 struct SCColor {
30 float red, green, blue, alpha;
32 typedef struct SCColor SCColor;
34 inline SCColor SCMakeColor(float red, float green, float blue, float alpha)
36 SCColor sccolor;
37 sccolor.red = red;
38 sccolor.green = green;
39 sccolor.blue = blue;
40 sccolor.alpha = alpha;
41 return sccolor;
44 struct SCPoint {
45 float x, y;
48 inline SCPoint SCMakePoint(float x, float y)
50 SCPoint p;
51 p.x = x;
52 p.y = y;
53 return p;
56 struct SCRect {
57 float x, y, width, height;
60 inline SCRect SCRectUnion(SCRect a, SCRect b)
62 if (a.height <= 0. && a.width <= 0.) return b;
63 if (b.height <= 0. && b.width <= 0.) return a;
65 SCRect u;
66 u.x = sc_min(a.x, b.x);
67 u.y = sc_min(a.y, b.y);
68 u.width = sc_max(a.x + a.width, b.x + b.width) - u.x;
69 u.height = sc_max(a.y + a.height, b.y + b.height) - u.y;
70 return u;
73 inline bool SCRectsDoIntersect(SCRect a, SCRect b)
75 if ((a.x + a.width) <= b.x) return false;
76 if ((a.y + a.height) <= b.y) return false;
77 if (a.x >= (b.x + b.width)) return false;
78 if (a.y >= (b.y + b.height)) return false;
79 return true;
82 inline SCRect SCMakeRect(float x, float y, float width, float height)
84 SCRect r;
85 r.x = x; r.y = y; r.width = width; r.height = height;
86 return r;
89 inline bool SCPointInRect(SCPoint p, SCRect r)
91 return
92 p.x >= r.x && p.x <= r.x + r.width
93 && p.y >= r.y && p.y <= r.y + r.height;