summaryrefslogtreecommitdiff
blob: 2ea7096208b4f67cf98da40397afcad0be62a17f (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
#include "../include/extract.h"
#include "document.h"

static inline double
mind(double a, double b)
{
    return (a < b) ? a : b;
}

static inline double
maxd(double a, double b)
{
    return (a > b) ? a : b;
}

rect_t extract_rect_intersect(rect_t a, rect_t b)
{
    rect_t r;

    r.min.x = maxd(a.min.x, b.min.x);
    r.min.y = maxd(a.min.y, b.min.y);
    r.max.x = mind(a.max.x, b.max.x);
    r.max.y = mind(a.max.y, b.max.y);

    return r;
}

rect_t extract_rect_union(rect_t a, rect_t b)
{
    rect_t r;

    r.min.x = mind(a.min.x, b.min.x);
    r.min.y = mind(a.min.y, b.min.y);
    r.max.x = maxd(a.max.x, b.max.x);
    r.max.y = maxd(a.max.y, b.max.y);

    return r;
}

int extract_rect_contains_rect(rect_t a, rect_t b)
{
    if (a.min.x > b.min.x)
        return 0;
    if (a.min.y > b.min.y)
        return 0;
    if (a.max.x < b.max.x)
        return 0;
    if (a.max.y < b.max.y)
        return 0;

    return 1;
}

int extract_rect_valid(rect_t a)
{
	return (a.min.x <= a.max.x && a.min.y <= a.max.y);
}