-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.odin
53 lines (39 loc) · 1.21 KB
/
util.odin
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
package msc
import "core:strings"
between :: proc(a: $T, x: T, b: T) -> b32 {
return a < x && x < b
}
between_equal :: proc(a: $T, x: T, b: T) -> b32 {
return a <= x && x <= b
}
between_equal_left :: proc(a: $T, x: T, b: T) -> b32 {
return a <= x && x < b
}
between_equal_right :: proc(a: $T, x: T, b: T) -> b32 {
return a < x && x <= b
}
point_in_rect :: #force_inline proc(px, py: int, rect: Rect) -> b32 {
return(
between_equal_left(rect.x, px, rect.x + rect.w) &&
between_equal_left(rect.y, py, rect.y + rect.h) \
)
}
x1 :: #force_inline proc(rect: Rect) -> int {
return rect.x + rect.w
}
y1 :: #force_inline proc(rect: Rect) -> int {
return rect.y + rect.h
}
u16_bytes_to_u16 :: proc(bytes: []u8, allocator := context.temp_allocator) -> ([]u16, bool) {
if len(bytes) % 2 != 0 do return {}, false
result := make([]u16, len(bytes) / 2, allocator)
for index := 0; index < len(result); index += 1 {
result[index] = u16(bytes[index * 2]) | u16(bytes[index * 2 + 1]) << 8
}
return result, true
}
u16_bytes_to_u8 :: proc(bytes: []u8, allocator := context.temp_allocator) -> (string, bool) {
if len(bytes) % 2 != 0 do return {}, false
result := make([]u8, len(bytes) / 2, allocator)
return {}, true
}