haiku/headers/private/interface/clipping.h
Stefano Ceccherini d4400ac125 A line can be too a valid rect.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3816 a95241bf-73f2-0310-859d-f6bbb57e9c96
2003-07-03 06:29:06 +00:00

85 lines
1.7 KiB
C

#ifndef __CLIPPING_H
#define __CLIPPING_H
static inline clipping_rect
union_rect(clipping_rect r1, clipping_rect r2)
{
clipping_rect rect;
rect.left = min_c(r1.left, r2.left);
rect.top = min_c(r1.top, r2.top);
rect.right = max_c(r1.right, r2.right);
rect.bottom = max_c(r1.bottom, r2.bottom);
return rect;
}
// Returns the intersection of the given rects.
// The caller should check if the returned rect is valid. If it isn't valid,
// then the two rectangles don't intersect.
static inline clipping_rect
sect_rect(clipping_rect r1, clipping_rect r2)
{
clipping_rect rect;
rect.left = max_c(r1.left, r2.left);
rect.top = max_c(r1.top, r2.top);
rect.right = min_c(r1.right, r2.right);
rect.bottom = min_c(r1.bottom, r2.bottom);
return rect;
}
static inline BRect
to_BRect(clipping_rect rect)
{
return BRect(rect.left, rect.top, rect.right, rect.bottom);
}
static inline clipping_rect
to_clipping_rect(BRect rect)
{
clipping_rect clipRect;
clipRect.left = (int32)floor(rect.left);
clipRect.top = (int32)floor(rect.top);
clipRect.right = (int32)ceil(rect.right);
clipRect.bottom = (int32)ceil(rect.bottom);
return clipRect;
}
static inline bool
point_in(clipping_rect rect, int32 px, int32 py)
{
if (px >= rect.left && px <= rect.right
&& py >= rect.top && py <= rect.bottom)
return true;
return false;
}
static inline bool
point_in(clipping_rect rect, BPoint pt)
{
if (pt.x >= rect.left && pt.x <= rect.right
&& pt.y >= rect.top && pt.y <= rect.bottom)
return true;
return false;
}
static inline bool
valid_rect(clipping_rect rect)
{
if (rect.left <= rect.right && rect.top <= rect.bottom)
return true;
return false;
}
#endif // __CLIPPING_H