1use super::bindings::{miracle_point_t, miracle_size_t};
2use glam::Mat4;
3
4#[derive(Debug, Clone, Copy, PartialEq, Default)]
6pub struct Rect {
7 pub x: f32,
8 pub y: f32,
9 pub width: f32,
10 pub height: f32,
11}
12
13impl Rect {
14 pub const fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
16 Self {
17 x,
18 y,
19 width,
20 height,
21 }
22 }
23
24 pub fn from_array(arr: [f32; 4]) -> Self {
26 Self {
27 x: arr[0],
28 y: arr[1],
29 width: arr[2],
30 height: arr[3],
31 }
32 }
33
34 pub fn to_array(self) -> [f32; 4] {
36 [self.x, self.y, self.width, self.height]
37 }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
42pub struct Size {
43 pub width: i32,
44 pub height: i32,
45}
46
47impl Size {
48 pub const fn new(width: i32, height: i32) -> Self {
50 Self { width, height }
51 }
52}
53
54impl From<Size> for miracle_size_t {
55 fn from(value: Size) -> Self {
56 Self {
57 w: value.width,
58 h: value.height,
59 }
60 }
61}
62
63impl From<miracle_size_t> for Size {
64 fn from(value: miracle_size_t) -> Self {
65 Self {
66 width: value.w,
67 height: value.h,
68 }
69 }
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
74pub struct Point {
75 pub x: i32,
76 pub y: i32,
77}
78
79impl Point {
80 pub const fn new(x: i32, y: i32) -> Self {
82 Self { x, y }
83 }
84}
85
86impl From<Point> for miracle_point_t {
87 fn from(value: Point) -> Self {
88 Self {
89 x: value.x,
90 y: value.y,
91 }
92 }
93}
94
95impl From<miracle_point_t> for Point {
96 fn from(value: miracle_point_t) -> Self {
97 Self {
98 x: value.x,
99 y: value.y,
100 }
101 }
102}
103
104#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
106pub struct Rectangle {
107 pub x: i32,
108 pub y: i32,
109 pub width: i32,
110 pub height: i32,
111}
112
113impl Rectangle {
114 pub const fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
116 Self {
117 x,
118 y,
119 width,
120 height,
121 }
122 }
123}
124
125pub fn mat4_from_f32_array(arr: [f32; 16]) -> Mat4 {
127 Mat4::from_cols_array(&arr)
128}
129
130pub fn mat4_to_f32_array(mat: Mat4) -> [f32; 16] {
132 mat.to_cols_array()
133}