mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
40 lines
1,003 B
R
40 lines
1,003 B
R
|
#include "qwaq-rect.h"
|
||
|
|
||
|
Rect
|
||
|
clipRect (Rect clipRect, Rect rect)
|
||
|
{
|
||
|
if (rect.offset.x < clipRect.offset.x) {
|
||
|
int dist = clipRect.offset.x - rect.offset.x;
|
||
|
rect.offset.x += dist;
|
||
|
rect.extent.width -= dist;
|
||
|
}
|
||
|
if (rect.offset.y < clipRect.offset.y) {
|
||
|
int dist = clipRect.offset.y - rect.offset.y;
|
||
|
rect.offset.y += dist;
|
||
|
rect.extent.height -= dist;
|
||
|
}
|
||
|
if (rect.offset.x + rect.extent.width > clipRect.extent.width) {
|
||
|
rect.extent.width = clipRect.extent.width - rect.offset.x;
|
||
|
}
|
||
|
if (rect.offset.y + rect.extent.height > clipRect.extent.height) {
|
||
|
rect.extent.height = clipRect.extent.height - rect.offset.y;
|
||
|
}
|
||
|
return rect;
|
||
|
}
|
||
|
|
||
|
Rect
|
||
|
makeRect (int xpos, int ypos, int xlen, int ylen)
|
||
|
{
|
||
|
Rect rect = {{xpos, ypos}, {xlen, ylen}};
|
||
|
return rect;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
rectContainsPoint (Rect *rect, Point *point)
|
||
|
{
|
||
|
return ((point.x >= rect.offset.x
|
||
|
&& point.x < rect.offset.x + rect.extent.width)
|
||
|
&& (point.y >= rect.offset.y
|
||
|
&& point.y < rect.offset.y + rect.extent.height));
|
||
|
}
|