imath_traits/
impl_array.rs1pub use crate::*;
2use std::fmt;
3use std::ops::Sub;
4
5#[derive(Copy, Clone, PartialEq, Hash, Debug)]
6pub struct Box1<T>
7where
8 T: Sub<Output = T> + Copy + fmt::Debug,
9{
10 pub min: T,
11 pub max: T,
12}
13
14impl<T> Bound1<T> for Box1<T>
15where
16 T: Sub<Output = T> + Copy + fmt::Debug,
17{
18 fn from_slice(slice: &[T; 2]) -> Self {
19 Box1::<T> {
20 min: slice[0],
21 max: slice[1],
22 }
23 }
24
25 fn as_slice(&self) -> &[T; 2] {
26 unsafe { &*(self.as_ptr() as *const [T; 2]) }
27 }
28
29 fn as_ptr(&self) -> *const T {
30 self as *const Box1<T> as *const T
31 }
32}
33
34#[derive(Copy, Clone, PartialEq, Hash, Debug)]
35pub struct Box2<T>
36where
37 T: Sub<Output = T> + Copy + fmt::Debug,
38{
39 pub min: [T; 2],
40 pub max: [T; 2],
41}
42
43impl<T> Bound2<T> for Box2<T>
44where
45 T: Sub<Output = T> + Copy + fmt::Debug,
46{
47 fn from_slice(slice: &[T; 4]) -> Self {
48 Box2::<T> {
49 min: [slice[0], slice[1]],
50 max: [slice[2], slice[3]],
51 }
52 }
53
54 fn as_slice(&self) -> &[T; 4] {
55 unsafe { &*(self.as_ptr() as *const [T; 4]) }
56 }
57
58 fn as_ptr(&self) -> *const T {
59 self as *const Box2<T> as *const T
60 }
61}
62
63pub type Box2i = Box2<i32>;
64pub type Box2f = Box2<f32>;
65pub type Box2d = Box2<f64>;
66
67#[derive(Copy, Clone, PartialEq, Hash, Debug)]
68pub struct Box3<T>
69where
70 T: Copy,
71{
72 pub min: [T; 3],
73 pub max: [T; 3],
74}
75
76impl<T> Bound3<T> for Box3<T>
77where
78 T: Sub<Output = T> + Copy + fmt::Debug,
79{
80 fn from_slice(slice: &[T; 6]) -> Self {
81 Box3::<T> {
82 min: [slice[0], slice[1], slice[2]],
83 max: [slice[3], slice[4], slice[5]],
84 }
85 }
86
87 fn as_slice(&self) -> &[T; 6] {
88 unsafe { &*(self.as_ptr() as *const [T; 6]) }
89 }
90
91 fn as_ptr(&self) -> *const T {
92 self as *const Box3<T> as *const T
93 }
94}
95
96pub type Box3i = Box3<i32>;
97pub type Box3f = Box3<f32>;
98pub type Box3d = Box3<f64>;