2020-03-09 17:39:18 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2020-03-12 17:09:55 +00:00
|
|
|
Point makePoint (int x, int y)
|
|
|
|
{
|
2020-03-13 01:00:05 +00:00
|
|
|
return {x, y};
|
2020-03-12 17:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Extent makeExtent (int width, int height)
|
|
|
|
{
|
2020-03-13 01:00:05 +00:00
|
|
|
return {width, height};
|
2020-03-12 17:09:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 04:51:14 +00:00
|
|
|
Extent mergeExtents (Extent a, Extent b)
|
|
|
|
{
|
|
|
|
return { a.width < b.width ? b.width : a.width,
|
|
|
|
a.height < b.height ? b.height : a.height };
|
|
|
|
}
|
|
|
|
|
2020-03-09 17:39:18 +00:00
|
|
|
int
|
2020-03-19 06:53:20 +00:00
|
|
|
rectContainsPoint (Rect rect, Point point)
|
2020-03-09 17:39:18 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|