blob: 093aea02804fe2442b445839df1748d51fb1a1f9 (
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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
struct RectWithSize {
vec2 p0;
vec2 size;
};
struct RectWithEndpoint {
vec2 p0;
vec2 p1;
};
RectWithEndpoint to_rect_with_endpoint(RectWithSize rect) {
RectWithEndpoint result;
result.p0 = rect.p0;
result.p1 = rect.p0 + rect.size;
return result;
}
RectWithSize to_rect_with_size(RectWithEndpoint rect) {
RectWithSize result;
result.p0 = rect.p0;
result.size = rect.p1 - rect.p0;
return result;
}
RectWithSize intersect_rects(RectWithSize a, RectWithSize b) {
RectWithSize result;
result.p0 = max(a.p0, b.p0);
result.size = min(a.p0 + a.size, b.p0 + b.size) - result.p0;
return result;
}
float point_inside_rect(vec2 p, vec2 p0, vec2 p1) {
vec2 s = step(p0, p) - step(p1, p);
return s.x * s.y;
}
|