rustyray_sys/
rectangle.rs1use std::fmt::Display;
2
3use crate::vector::*;
4
5#[repr(C)]
6#[derive(Debug, Clone, Copy)]
7pub struct Rectangle {
8 pub x: f32,
9 pub y: f32,
10 pub width: f32,
11 pub height: f32,
12}
13
14impl Rectangle {
15 pub 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 position(&self) -> Vector2 {
26 Vector2 {
27 x: self.x,
28 y: self.y,
29 }
30 }
31
32 pub fn size(&self) -> Vector2 {
34 Vector2 {
35 x: self.width,
36 y: self.height,
37 }
38 }
39}
40
41impl Display for Rectangle {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 f.write_str(
44 format!(
45 "Rectangle{{x: {}, y: {}, width: {}, height: {}}}",
46 self.x, self.y, self.width, self.height
47 )
48 .as_str(),
49 )
50 }
51}