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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
pub use crate::*;
use std::fmt;
use std::ops::Sub;
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
pub struct Box1<T>
where
T: Sub<Output = T> + Copy + fmt::Debug,
{
pub min: T,
pub max: T,
}
impl<T> Bound1<T> for Box1<T>
where
T: Sub<Output = T> + Copy + fmt::Debug,
{
fn from_slice(slice: &[T; 2]) -> Self {
Box1::<T> {
min: slice[0],
max: slice[1],
}
}
fn as_slice(&self) -> &[T; 2] {
unsafe { &*(self.as_ptr() as *const [T; 2]) }
}
fn as_ptr(&self) -> *const T {
self as *const Box1<T> as *const T
}
}
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
pub struct Box2<T>
where
T: Sub<Output = T> + Copy + fmt::Debug,
{
pub min: [T; 2],
pub max: [T; 2],
}
impl<T> Bound2<T> for Box2<T>
where
T: Sub<Output = T> + Copy + fmt::Debug,
{
fn from_slice(slice: &[T; 4]) -> Self {
Box2::<T> {
min: [slice[0], slice[1]],
max: [slice[2], slice[3]],
}
}
fn as_slice(&self) -> &[T; 4] {
unsafe { &*(self.as_ptr() as *const [T; 4]) }
}
fn as_ptr(&self) -> *const T {
self as *const Box2<T> as *const T
}
}
pub type Box2i = Box2<i32>;
pub type Box2f = Box2<f32>;
pub type Box2d = Box2<f64>;
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
pub struct Box3<T>
where
T: Copy,
{
pub min: [T; 3],
pub max: [T; 3],
}
impl<T> Bound3<T> for Box3<T>
where
T: Sub<Output = T> + Copy + fmt::Debug,
{
fn from_slice(slice: &[T; 6]) -> Self {
Box3::<T> {
min: [slice[0], slice[1], slice[2]],
max: [slice[3], slice[4], slice[5]],
}
}
fn as_slice(&self) -> &[T; 6] {
unsafe { &*(self.as_ptr() as *const [T; 6]) }
}
fn as_ptr(&self) -> *const T {
self as *const Box3<T> as *const T
}
}
pub type Box3i = Box3<i32>;
pub type Box3f = Box3<f32>;
pub type Box3d = Box3<f64>;