1use serde::{
2 Deserialize,
3 Serialize,
4};
5
6use crate::vector::Vector3;
7
8#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
10pub struct Item {
11 pub id: i32,
13 pub size_cube: Vector3<u32>,
15 pub weight: u32,
17 pub order: u32,
19}
20impl Item {
21 pub const fn new(id: i32, position: Vector3<u32>, weight: u32, order: u32) -> Self {
23 Self {
24 id,
25 size_cube: position,
26 weight,
27 order,
28 }
29 }
30 pub fn rotation(&self) -> Vec<Vector3<u32>> {
32 let (x, y, z) = (self.size_cube.x, self.size_cube.y, self.size_cube.z);
33 let first_rotation = Vector3::new(y, x, z);
34 let second_rotation = Vector3::new(x, z, y);
35 let four_rotation = Vector3::new(z, x, y);
36 let five_rotation = Vector3::new(y, z, x);
37 let sixs_rotation = Vector3::new(z, y, x);
38 let normal_rotation = Vector3::new(x, y, z);
39 vec![
40 normal_rotation,
41 first_rotation,
42 second_rotation,
43 four_rotation,
44 five_rotation,
45 sixs_rotation,
46 ]
47 }
48 pub fn rotation_v2(&self) -> Vec<Item> {
50 let (x, y, z) = (self.size_cube.x, self.size_cube.y, self.size_cube.z);
51 let first_rotation = Item::new(self.id, Vector3::new(y, x, z), self.weight, self.order);
52 let second_rotation = Item::new(self.id, Vector3::new(x, z, y), self.weight, self.order);
53 let four_rotation = Item::new(self.id, Vector3::new(z, x, y), self.weight, self.order);
54 let five_rotation = Item::new(self.id, Vector3::new(y, z, x), self.weight, self.order);
55 let sixs_rotation = Item::new(self.id, Vector3::new(z, y, x), self.weight, self.order);
56 let normal_rotation = Item::new(self.id, Vector3::new(x, y, z), self.weight, self.order);
57 vec![
58 normal_rotation,
59 first_rotation,
60 second_rotation,
61 four_rotation,
62 five_rotation,
63 sixs_rotation,
64 ]
65 }
66 pub const fn volume_item(&self) -> u32 {
68 self.size_cube.x * self.size_cube.y * self.size_cube.z
69 }
70}
71#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct ItemsPlaced {
74 pub position: Vector3<u32>,
76 pub item: Item,
78}
79impl ItemsPlaced {
80 pub const fn new(position: Vector3<u32>, item: Item) -> Self {
82 Self { position, item }
84 }
85}