mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[common] rects: add rectsRejectContained function
This function will remove rectangles in a list that are entirely contained in another rectangle in the same list.
This commit is contained in:
parent
566c89e9d8
commit
e945955d13
@ -47,5 +47,6 @@ void rectsFramebufferToBuffer(FrameDamageRect * rects, int count,
|
|||||||
const FrameBuffer * frame, int srcStride);
|
const FrameBuffer * frame, int srcStride);
|
||||||
|
|
||||||
int rectsMergeOverlapping(FrameDamageRect * rects, int count);
|
int rectsMergeOverlapping(FrameDamageRect * rects, int count);
|
||||||
|
int rectsRejectContained(FrameDamageRect * rects, int count);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -201,7 +201,7 @@ void rectsFramebufferToBuffer(FrameDamageRect * rects, int count,
|
|||||||
framebuffer_get_buffer(frame), srcStride, &data, fbRowStart, NULL);
|
framebuffer_get_buffer(frame), srcStride, &data, fbRowStart, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rectIntersects(const FrameDamageRect * r1, const FrameDamageRect * r2)
|
inline static bool rectIntersects(const FrameDamageRect * r1, const FrameDamageRect * r2)
|
||||||
{
|
{
|
||||||
return r1->x < r2->x + r2->width &&
|
return r1->x < r2->x + r2->width &&
|
||||||
r1->x + r1->width > r2->x &&
|
r1->x + r1->width > r2->x &&
|
||||||
@ -242,3 +242,29 @@ int rectsMergeOverlapping(FrameDamageRect * rects, int count)
|
|||||||
rects[o++] = rects[i];
|
rects[o++] = rects[i];
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static bool rectContains(const FrameDamageRect * r1, const FrameDamageRect * r2)
|
||||||
|
{
|
||||||
|
return r1->x <= r2->x &&
|
||||||
|
r1->y <= r2->y &&
|
||||||
|
r1->x + r1->width >= r2->x + r2->width &&
|
||||||
|
r1->y + r1->height >= r2->x + r2->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rectsRejectContained(FrameDamageRect * rects, int count)
|
||||||
|
{
|
||||||
|
bool removed[count];
|
||||||
|
memset(removed, 0, sizeof(removed));
|
||||||
|
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
if (!removed[i])
|
||||||
|
for (int j = 0; j < count; ++j)
|
||||||
|
if (!removed[j] && j != i && rectContains(rects + i, rects + j))
|
||||||
|
removed[j] = true;
|
||||||
|
|
||||||
|
int o = 0;
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
if (!removed[i])
|
||||||
|
rects[o++] = rects[i];
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user