-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregion.c
More file actions
45 lines (34 loc) · 737 Bytes
/
region.c
File metadata and controls
45 lines (34 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdbool.h>
#include "pos.h"
#include "region.h"
bool region_contains(const region_t *re, int x, int y)
{
region_t sorted = *re;
point_sort_full(&sorted.begin, &sorted.end);
const struct
{
bool x, y;
} in = {
sorted.begin.x <= x && x <= sorted.end.x,
sorted.begin.y <= y && y <= sorted.end.y
};
switch(re->type){
case REGION_LINE:
return in.y;
case REGION_COL:
return in.y && in.x;
case REGION_CHAR:
if(!in.y)
return false;
if(re->begin.y == re->end.y)
return in.x;
sorted = *re;
point_sort_y(&sorted.begin, &sorted.end);
if(y == sorted.begin.y)
return x >= sorted.begin.x;
if(y == sorted.end.y)
return x <= sorted.end.x;
return true;
}
return false;
}