1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Module: sageRect.h |
---|
5 | * Author : Byungil Jeong |
---|
6 | * |
---|
7 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
8 | * University of Illinois at Chicago |
---|
9 | * |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * Redistribution and use in source and binary forms, with or without |
---|
13 | * modification, are permitted provided that the following conditions are met: |
---|
14 | * |
---|
15 | * * Redistributions of source code must retain the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer. |
---|
17 | * * Redistributions in binary form must reproduce the above |
---|
18 | * copyright notice, this list of conditions and the following disclaimer |
---|
19 | * in the documentation and/or other materials provided with the distribution. |
---|
20 | * * Neither the name of the University of Illinois at Chicago nor |
---|
21 | * the names of its contributors may be used to endorse or promote |
---|
22 | * products derived from this software without specific prior written permission. |
---|
23 | * |
---|
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
35 | * |
---|
36 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
37 | * http://www.evl.uic.edu/cavern/forum/ |
---|
38 | * |
---|
39 | *****************************************************************************/ |
---|
40 | |
---|
41 | #ifndef _SAGE_RECT_H |
---|
42 | #define _SAGE_RECT_H |
---|
43 | |
---|
44 | #include "sageBase.h" |
---|
45 | |
---|
46 | #define LOWER_LEFT 0 |
---|
47 | #define LOWER_RIGHT 1 |
---|
48 | #define UPPER_RIGHT 2 |
---|
49 | #define UPPER_LEFT 3 |
---|
50 | |
---|
51 | #define LEFT_EDGE 0 |
---|
52 | #define RIGHT_EDGE 1 |
---|
53 | #define BOTTOM_EDGE 2 |
---|
54 | #define TOP_EDGE 3 |
---|
55 | #define ON_RECT 4 |
---|
56 | |
---|
57 | enum sageRotation {CCW_ZERO, CCW_90, CCW_180, CCW_270}; |
---|
58 | |
---|
59 | sageRotation operator+(sageRotation r1, sageRotation r2); |
---|
60 | sageRotation operator-(sageRotation r1, sageRotation r2); |
---|
61 | |
---|
62 | class sageRect { |
---|
63 | public: |
---|
64 | int x, y, width, height; |
---|
65 | float left, right, bottom, top; |
---|
66 | protected: |
---|
67 | sageRotation orientation; |
---|
68 | |
---|
69 | public: |
---|
70 | sageRect() : x(0), y(0), width(0), height(0), |
---|
71 | left(0.0), right(1.0), bottom(0.0), top(1.0), orientation(CCW_ZERO) {} |
---|
72 | |
---|
73 | sageRect(float l, float r, float b, float t) |
---|
74 | : x(0), y(0), width(0), height(0), |
---|
75 | left(l), right(r), bottom(b), top(t), orientation(CCW_ZERO) {} |
---|
76 | |
---|
77 | sageRect(int rx, int ry, int rw, int rh) |
---|
78 | : x(rx), y(ry), width(rw), height(rh), |
---|
79 | left(0.0), right(1.0), bottom(0.0), top(1.0), orientation(CCW_ZERO) {} |
---|
80 | |
---|
81 | ~sageRect() {} |
---|
82 | |
---|
83 | //void operator= (sageRect &rect); |
---|
84 | void operator+= (sageRect &rect); |
---|
85 | sageRect operator+ (sageRect &rect); |
---|
86 | sageRect operator/ (float div); |
---|
87 | sageRect operator/ (sageRect &rect); |
---|
88 | void operator/= (sageRect &rect); |
---|
89 | sageRect operator* (sageRect &rect); |
---|
90 | void operator*= (sageRect &rect); |
---|
91 | |
---|
92 | void updateBoundary(); |
---|
93 | void updateBoundary(sageRect &rect); |
---|
94 | void moveOrigin(sageRect &rect); |
---|
95 | void scale(float r); |
---|
96 | void scale(float sx, float sy); |
---|
97 | void translate(int x, int y); |
---|
98 | void translate(sageRect &rect); |
---|
99 | void rotate(sageRotation rot); |
---|
100 | void setOrientation(sageRotation ori) { orientation = ori; } |
---|
101 | inline sageRotation getOrientation() { return orientation; } |
---|
102 | void resetOrientation() { rotate(CCW_ZERO - orientation); } |
---|
103 | void shrink(float x, float y); |
---|
104 | void locate(); |
---|
105 | void normalize(sageRect &rect); |
---|
106 | int normalize(float x, float y); |
---|
107 | |
---|
108 | bool isOverLap(float l, float r, float b, float t, sageRect &com); |
---|
109 | bool isOverLapX(float l, float r, sageRect &com); |
---|
110 | bool isOverLapY(float b, float t, sageRect &com); |
---|
111 | |
---|
112 | bool isOverLap(sageRect &rect); |
---|
113 | int isOverLap(sageRect &rect, float threshold); |
---|
114 | bool isOverLap(sageRect &rect, sageRect &com); |
---|
115 | bool isOverLapX(int x2, int w2, sageRect &com); |
---|
116 | bool isOverLapY(int y2, int h2, sageRect &com); |
---|
117 | |
---|
118 | bool isInRect(float x, float y); |
---|
119 | bool isInRect(int x, int y); |
---|
120 | bool isInRect(sageRect &rect); |
---|
121 | void genTexCoord(int corner, float &x, float &y); |
---|
122 | void sprintRect(char *str); |
---|
123 | void sscanRect(char *str); |
---|
124 | |
---|
125 | inline int halfWidth() { return width/2; } |
---|
126 | inline int halfHeight() { return height/2; } |
---|
127 | inline int centerX() { return x + halfWidth(); } |
---|
128 | inline int centerY() { return y + halfHeight(); } |
---|
129 | //int mask(sageRect &rect); // crop by the rect which has normalized coordinates |
---|
130 | bool crop(sageRect &rect); |
---|
131 | }; |
---|
132 | |
---|
133 | #endif |
---|