aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/wasabi_std_rect.cpp
blob: a5040da0e04cc99fafe6bfdd69026bd4eee90c3f (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "wasabi_std_rect.h"
#include <bfc/platform/minmax.h>
#include <bfc/std_mem.h>

bool  Wasabi::Std::rectIntersect(const RECT &i1, const RECT &i2, RECT *intersection)
{
	RECT out;
	out.left   = MAX(i1.left, i2.left);
	out.right  = MIN(i1.right, i2.right);
	out.top    = MAX(i1.top, i2.top);
	out.bottom = MIN(i1.bottom, i2.bottom);

	if (intersection != NULL) *intersection = out;
	return (out.left < out.right && out.top < out.bottom);
}

bool  Wasabi::Std::pointInRect(const RECT &r, const POINT &p)
{
	if (p.x < r.left ||
	    p.x >= r.right ||
	    p.y < r.top ||
	    p.y >= r.bottom) return 0;
	return true;
}

void  Wasabi::Std::setRect(RECT *r, int left, int top, int right, int bottom)
{
	r->left = left;
	r->top = top;
	r->right = right;
	r->bottom = bottom;

}

RECT  Wasabi::Std::makeRect(int left, int top, int right, int bottom)
{
	RECT r;
	r.left = left;
	r.top = top;
	r.right = right;
	r.bottom = bottom;
	return r;

}

POINT  Wasabi::Std::makePoint(int x, int y)
{
	POINT p = { x, y };
	return p;
}

void  Wasabi::Std::offsetRect(RECT *r, int x, int y)
{
	r->left += x;
	r->right += x;
	r->top += y;
	r->bottom += y;
}

bool  Wasabi::Std::rectEqual(const RECT &a, const RECT &b)
{
	return !MEMCMP(&a, &b, sizeof(RECT));
}

bool  Wasabi::Std::rectEqual(const RECT *a, const RECT *b)
{
	return !MEMCMP(a, b, sizeof(RECT));
}

void  Wasabi::Std::scaleRect(RECT *r, double scale)
{
  r->left =(long)(r->left * scale + 0.5);
  r->right = (long)(r->right * scale + 0.5);
  r->bottom = (long)(r->bottom * scale + 0.5);
  r->top = (long)(r->top * scale + 0.5);
}