nd_vector/lib.rs
1use std::num::NonZeroUsize;
2
3use serde::{Deserialize, Serialize};
4use usage_types::full_shape::FullShape;
5
6mod air;
7pub use air::Air;
8#[cfg(feature = "bevy")]
9pub mod bevy;
10#[cfg(feature = "bevy")]
11pub use bevy::mesh::Transparent;
12pub mod display;
13pub mod prelude;
14pub mod modify;
15pub mod construct;
16pub mod usage_types;
17pub mod retrieve;
18
19pub type DefinedShape = Vec<NonZeroUsize>;
20
21/// ```text
22/// ▣▦▥▩╱̅̅╲▜▄‾‾‾‾█╲▜█▀▀▀▀‾̅̅╲‾▄█▀▀▀▙╲▀▀▜▄▀▀‾̅̅╲‾▄█▀▀▀▙╲▜█▀▀▀▇‾╲
23/// ▧◤ ╱╲╱╲ ▜▄ █ ╲▜█▀▀▀ ╲▜ ╲ ▜▄ ╲▜ █╲▜█▄▄▛ ╲
24/// ╱╲╱╲╱╲__̲▜██__̲╲̲▜█▄▄▄▄_̲╲_̲▀▇▇▀_̲╲___̲▜▄__̲╲_̲▀▇▇▀_̲_̲╲̲▀█▄_̲▀▙_̲╲
25/// ╲╱╲╱╲̲╱_̲╱_̲╱_̲╱_̲╱ ▟███▙ ╱▟███▙ ╱ ▟▛ ╱ ▟██▇▄ ̲╱_̲╱_̲╱_̲╱_╱
26/// ╲╱╲̲╱_̲╱_̲╱_̲╱_̲╱ ▟▛ ▄▄ ╱▟█▄▄▛ ╱ ▟▛ ╱ ▟▛ ▟▛ ̲╱_̲╱_̲╱_̲╱_╱
27/// ╲̲╱_̲╱_̲╱_̲╱_̲╱__̲▜██▛_̲╱▟█_̲▜▙╱__▟▛__̲╱_̲▟██▇▀̲▀__̲╱_̲╱_̲╱_̲╱_╱
28///
29/// ```
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct VectorGrid<ItemType> {
33 /// The defined shape of a VectorGrid,
34 /// which is it's size along every axis, EXEPT FOR THE LAST ONE! The last axis is determined by the length of the vector.
35 /// ```text
36 /// _________
37 /// ╱__╱__╱__╱╲ For example, lets say that we have this 3 x 1 x 2 block.
38 /// ╱__╱__╱__╱╲╱ As a VectorGrid, its defined shape would be [3, 1], and the vector's length, 6.
39 /// 1 ╲__╲__╲__╲╱
40 /// 3
41 /// ```
42 ///
43 defined_shape: DefinedShape,
44 /// The vector of the VectorGrid! These are all the items in order.
45 /// ```text
46 /// This is what it looks like as a normal vector:
47 /// ┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
48 /// │ #1 │ #2 │ #3 │ #4 │ #5 │ #6 │ #7 │ #8 │ #9 │ #10│ #11│ #12│ #13│ #14│
49 /// └────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
50 ///
51 /// But with a defined shape of, lets say [4], then it would look like this:
52 /// ┌────┬────┬────┬────┐
53 /// │ #1 │ #2 │ #3 │ #4 │
54 /// ├────┼────┼────┼────┤
55 /// │ #5 │ #6 │ #7 │ #8 │
56 /// ├────┼────┼────┼────┤
57 /// │ #9 │ #10│ #11│ #12│
58 /// ├────┼────┼────┴────┘
59 /// │ #13│ #14│
60 /// └────┴────┘
61 /// ```
62 items: Vec<ItemType>
63}
64
65impl<ItemType> VectorGrid<ItemType> {
66
67 pub fn shape(&self) -> FullShape {
68 FullShape { defined: self.defined_shape.clone(), total_length: self.items.len() }
69 }
70
71 pub fn defined_shape(&self) -> &DefinedShape {
72 &self.defined_shape
73 }
74
75 pub fn defined_shape_usize(&self) -> Vec<usize> {
76 self.defined_shape.iter().map(|v| {v.get()}).collect()
77 }
78
79 pub fn defined_shape_isize(&self) -> Vec<isize> {
80 self.defined_shape.iter().map(|v| {v.get() as isize}).collect()
81 }
82
83 pub fn defined_shape_i32(&self) -> Vec<i32> {
84 self.defined_shape.iter().map(|v| {v.get() as i32}).collect()
85 }
86
87 pub fn items(&self) -> &Vec<ItemType> {
88 &self.items
89 }
90}