12 |
* different chunks of code and having to convert between them. |
* different chunks of code and having to convert between them. |
13 |
* |
* |
14 |
* Revision history: |
* Revision history: |
15 |
|
* v1.6 - fixed another bug in the IntersectRect method |
16 |
|
* v1.5 - fixed a bug in the IntersectRect method |
17 |
* v1.4 - added the UnionRect method |
* v1.4 - added the UnionRect method |
18 |
* v1.3 - added the IsRectEmpty and the IntersectRect methods |
* v1.3 - added the IsRectEmpty and the IntersectRect methods |
19 |
* v1.2 - added the setRect method |
* v1.2 - added the setRect method |
20 |
* v1.1 - added the PointInRect and the setRectEmpty methods |
* v1.1 - added the PointInRect and the setRectEmpty methods |
21 |
* |
* |
22 |
* @author <A href="mailto:vovansim@hotmail.com">Vovansim (aka Scorpion)</A> |
* @author <A href="mailto:vovansim@hotmail.com">Vovansim (aka Scorpion)</A> |
23 |
* @version 1.4 |
* @version 1.6 |
24 |
* @date June 6, 2003 |
* @date August 23, 2003 |
25 |
*/ |
*/ |
26 |
|
|
27 |
#include "IsoGeometryTools.h" |
#include "IsoGeometryTools.h" |
137 |
*/ |
*/ |
138 |
bool IntersectRect(RECT* destination, RECT* rectangle1, RECT* rectangle2) { |
bool IntersectRect(RECT* destination, RECT* rectangle1, RECT* rectangle2) { |
139 |
//Take care of the left edge of the rectangle: |
//Take care of the left edge of the rectangle: |
140 |
if(rectangle1->left > rectangle2->left && |
if(rectangle1->left >= rectangle2->left && |
141 |
rectangle1->left <= rectangle2->right) { |
rectangle1->left <= rectangle2->right) { |
142 |
destination->left = rectangle1->left; |
destination->left = rectangle1->left; |
143 |
} else if(rectangle2->left > rectangle1->left && |
} else if(rectangle2->left >= rectangle1->left && |
144 |
rectangle2->left <= rectangle1->right) { |
rectangle2->left <= rectangle1->right) { |
145 |
destination->left = rectangle2->left; |
destination->left = rectangle2->left; |
146 |
} else { |
} else { |
147 |
destination->left = 0; |
destination->left = (rectangle1->left > rectangle2->left) ? (rectangle1->left) : (rectangle2->left); |
148 |
} |
} |
149 |
|
|
150 |
//Take care of the top edge of the rectangle: |
//Take care of the top edge of the rectangle: |
151 |
if(rectangle1->top > rectangle2->top && |
if(rectangle1->top >= rectangle2->top && |
152 |
rectangle1->top <= rectangle2->bottom) { |
rectangle1->top <= rectangle2->bottom) { |
153 |
destination->top = rectangle1->top; |
destination->top = rectangle1->top; |
154 |
} else if(rectangle2->top > rectangle1->top && |
} else if(rectangle2->top >= rectangle1->top && |
155 |
rectangle2->top <= rectangle1->bottom) { |
rectangle2->top <= rectangle1->bottom) { |
156 |
destination->top = rectangle2->top; |
destination->top = rectangle2->top; |
157 |
} else { |
} else { |
158 |
destination->top = 0; |
destination->top = (rectangle1->top > rectangle2->top) ? (rectangle1->top) : (rectangle2->top); |
159 |
} |
} |
160 |
|
|
161 |
//Take care of the right edge of the rectangle: |
//Take care of the right edge of the rectangle: |
162 |
if(rectangle1->right > rectangle2->left && |
if(rectangle1->right >= rectangle2->left && |
163 |
rectangle1->right <= rectangle2->right) { |
rectangle1->right <= rectangle2->right) { |
164 |
destination->right = rectangle1->right; |
destination->right = rectangle1->right; |
165 |
} else if(rectangle2->right > rectangle1->left && |
} else if(rectangle2->right >= rectangle1->left && |
166 |
rectangle2->right <= rectangle1->right) { |
rectangle2->right <= rectangle1->right) { |
167 |
destination->right = rectangle2->right; |
destination->right = rectangle2->right; |
168 |
} else { |
} else { |
170 |
} |
} |
171 |
|
|
172 |
//Take care of the bottom edge of the rectangle: |
//Take care of the bottom edge of the rectangle: |
173 |
if(rectangle1->bottom > rectangle2->top && |
if(rectangle1->bottom >= rectangle2->top && |
174 |
rectangle1->bottom <= rectangle2->bottom) { |
rectangle1->bottom <= rectangle2->bottom) { |
175 |
destination->bottom = rectangle1->bottom; |
destination->bottom = rectangle1->bottom; |
176 |
} else if(rectangle2->bottom > rectangle1->top && |
} else if(rectangle2->bottom >= rectangle1->top && |
177 |
rectangle2->bottom <= rectangle1->bottom) { |
rectangle2->bottom <= rectangle1->bottom) { |
178 |
destination->bottom = rectangle2->bottom; |
destination->bottom = rectangle2->bottom; |
179 |
} else { |
} else { |