PatchworkOS
Loading...
Searching...
No Matches
rect.h File Reference
#include <stdint.h>
#include <sys/math.h>

Go to the source code of this file.

Data Structures

struct  rect_t
 
struct  rect_subtract_t
 

Macros

#define RECT_INIT(left, top, right, bottom)
 
#define RECT_INIT_DIM(x, y, width, height)
 
#define RECT_WIDTH(rect)   ((rect)->right - (rect)->left)
 
#define RECT_HEIGHT(rect)   ((rect)->bottom - (rect)->top)
 
#define RECT_AREA(rect)   (RECT_WIDTH(rect) * RECT_HEIGHT(rect))
 
#define RECT_HAS_NEGATIVE_DIMS(rect)   (RECT_WIDTH(rect) < 0 || RECT_HEIGHT(rect) < 0)
 
#define RECT_EXPAND_TO_CONTAIN(rect, other)
 
#define RECT_EQUAL(rect, other)
 
#define RECT_CONTAINS(rect, other)
 
#define RECT_CONTAINS_POINT(rect, point)
 
#define RECT_OVERLAP(rect, other)
 
#define RECT_OVERLAP_STRICT(rect, other)
 
#define RECT_FIT(rect, parent)
 
#define RECT_SHRINK(rect, margin)
 
#define RECT_EXPAND(rect, margin)
 
#define RECT_SUBTRACT(result, rect, other)
 
#define RECT_INTERSECT(dest, src1, src2)
 

Macro Definition Documentation

◆ RECT_AREA

#define RECT_AREA (   rect)    (RECT_WIDTH(rect) * RECT_HEIGHT(rect))

Definition at line 40 of file rect.h.

◆ RECT_CONTAINS

#define RECT_CONTAINS (   rect,
  other 
)
Value:
((rect)->left <= (rect)->right && (rect)->top <= (rect)->bottom && (other)->left <= (other)->right && \
(other)->top <= (other)->bottom && (other)->left >= (rect)->left && (other)->right <= (rect)->right && \
(other)->top >= (rect)->top && (other)->bottom <= (rect)->bottom)

Definition at line 56 of file rect.h.

◆ RECT_CONTAINS_POINT

#define RECT_CONTAINS_POINT (   rect,
  point 
)
Value:
((point)->x >= (rect)->left && (point)->x < (rect)->right && (point)->y >= (rect)->top && \
(point)->y < (rect)->bottom)
int64_t x
Definition main.c:152
int64_t y
Definition main.c:153

Definition at line 61 of file rect.h.

◆ RECT_EQUAL

#define RECT_EQUAL (   rect,
  other 
)
Value:
((other)->left == (rect)->left && (other)->right == (rect)->right && (other)->top == (rect)->top && \
(other)->bottom == (rect)->bottom)

Definition at line 52 of file rect.h.

◆ RECT_EXPAND

#define RECT_EXPAND (   rect,
  margin 
)
Value:
({ \
(rect)->left -= margin; \
(rect)->top -= margin; \
(rect)->right += margin; \
(rect)->bottom += margin; \
})

Definition at line 89 of file rect.h.

◆ RECT_EXPAND_TO_CONTAIN

#define RECT_EXPAND_TO_CONTAIN (   rect,
  other 
)
Value:
({ \
(rect)->left = MIN((rect)->left, (other)->left); \
(rect)->top = MIN((rect)->top, (other)->top); \
(rect)->right = MAX((rect)->right, (other)->right); \
(rect)->bottom = MAX((rect)->bottom, (other)->bottom); \
})
#define MIN(x, y)
Definition math.h:16
#define MAX(x, y)
Definition math.h:15

Definition at line 44 of file rect.h.

◆ RECT_FIT

#define RECT_FIT (   rect,
  parent 
)
Value:
({ \
(rect)->left = CLAMP((rect)->left, (parent)->left, (parent)->right); \
(rect)->top = CLAMP((rect)->top, (parent)->top, (parent)->bottom); \
(rect)->right = CLAMP((rect)->right, (parent)->left, (parent)->right); \
(rect)->bottom = CLAMP((rect)->bottom, (parent)->top, (parent)->bottom); \
})
#define CLAMP(x, low, high)
Definition math.h:17

Definition at line 73 of file rect.h.

◆ RECT_HAS_NEGATIVE_DIMS

#define RECT_HAS_NEGATIVE_DIMS (   rect)    (RECT_WIDTH(rect) < 0 || RECT_HEIGHT(rect) < 0)

Definition at line 42 of file rect.h.

◆ RECT_HEIGHT

#define RECT_HEIGHT (   rect)    ((rect)->bottom - (rect)->top)

Definition at line 39 of file rect.h.

◆ RECT_INIT

#define RECT_INIT (   left,
  top,
  right,
  bottom 
)
Value:
(rect_t) \
{ \
left, top, right, bottom, \
}
Definition rect.h:13

Definition at line 26 of file rect.h.

◆ RECT_INIT_DIM

#define RECT_INIT_DIM (   x,
  y,
  width,
  height 
)
Value:
(rect_t) \
{ \
(x), (y), (x) + (width), (y) + (height), \
}

Definition at line 32 of file rect.h.

◆ RECT_INTERSECT

#define RECT_INTERSECT (   dest,
  src1,
  src2 
)
Value:
({ \
(dest)->left = MAX((src1)->left, (src2)->left); \
(dest)->top = MAX((src1)->top, (src2)->top); \
(dest)->right = MIN((src1)->right, (src2)->right); \
(dest)->bottom = MIN((src1)->bottom, (src2)->bottom); \
})

Definition at line 129 of file rect.h.

◆ RECT_OVERLAP

#define RECT_OVERLAP (   rect,
  other 
)
Value:
(!((rect)->right <= (other)->left || (rect)->left >= (other)->right || (rect)->bottom <= (other)->top || \
(rect)->top >= (other)->bottom))

Definition at line 65 of file rect.h.

◆ RECT_OVERLAP_STRICT

#define RECT_OVERLAP_STRICT (   rect,
  other 
)
Value:
(!((rect)->right < (other)->left || (rect)->left > (other)->right || (rect)->bottom < (other)->top || \
(rect)->top > (other)->bottom))

Definition at line 69 of file rect.h.

◆ RECT_SHRINK

#define RECT_SHRINK (   rect,
  margin 
)
Value:
({ \
(rect)->left += margin; \
(rect)->top += margin; \
(rect)->right -= margin; \
(rect)->bottom -= margin; \
})

Definition at line 81 of file rect.h.

◆ RECT_SUBTRACT

#define RECT_SUBTRACT (   result,
  rect,
  other 
)
Value:
({ \
rect_subtract_t res = {.count = 0}; \
if (!RECT_OVERLAP(rect, other)) \
{ \
res.rects[0] = *(rect); \
res.count = 1; \
} \
else \
{ \
if ((other)->top > (rect)->top) \
{ \
res.rects[res.count++] = (rect_t){(rect)->left, (rect)->top, (rect)->right, (other)->top}; \
} \
if ((other)->bottom < (rect)->bottom) \
{ \
res.rects[res.count++] = (rect_t){(rect)->left, (other)->bottom, (rect)->right, (rect)->bottom}; \
} \
if ((other)->left > (rect)->left) \
{ \
res.rects[res.count++] = (rect_t){(rect)->left, MAX((rect)->top, (other)->top), (other)->left, \
MIN((rect)->bottom, (other)->bottom)}; \
} \
if ((other)->right < (rect)->right) \
{ \
res.rects[res.count++] = (rect_t){(other)->right, MAX((rect)->top, (other)->top), (rect)->right, \
MIN((rect)->bottom, (other)->bottom)}; \
} \
} \
*(result) = res; \
})
#define RECT_OVERLAP(rect, other)
Definition rect.h:65
uint8_t count
Definition rect.h:23
rect_t rects[4]
Definition rect.h:22
int32_t bottom
Definition rect.h:17
int32_t top
Definition rect.h:15

Definition at line 97 of file rect.h.

◆ RECT_WIDTH

#define RECT_WIDTH (   rect)    ((rect)->right - (rect)->left)

Definition at line 38 of file rect.h.