devela/num/geom/metric/
region.rs
1use crate::{Extent, Position, Stride};
7
8#[must_use]
10#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct Region<T, const D: usize> {
12 pub pos: Position<T, D>,
14 pub size: Extent<T, D>,
16}
17
18pub type Region2d<T> = Region<T, 2>;
20pub type Region3d<T> = Region<T, 3>;
22
23#[must_use]
31#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
32pub struct RegionStrided<T, const D: usize> {
33 pub region: Region<T, D>,
35 pub stride: Stride<T, D>,
37}
38
39impl<T, const D: usize> Region<T, D> {
42 pub const fn new(pos: Position<T, D>, size: Extent<T, D>) -> Self {
44 Self { pos, size }
45 }
46
47 #[must_use] #[rustfmt::skip]
49 pub fn position(&self) -> Position<T, D> where T: Clone { self.pos.clone() }
50 #[rustfmt::skip]
52 pub fn extent(&self) -> Extent<T, D> where T: Clone { self.size.clone() }
53}
54impl<T, const D: usize> From<(Position<T, D>, Extent<T, D>)> for Region<T, D> {
55 fn from(from: (Position<T, D>, Extent<T, D>)) -> Self {
56 Self::new(from.0, from.1)
57 }
58}
59impl<T, const D: usize> From<(Extent<T, D>, Position<T, D>)> for Region<T, D> {
60 fn from(from: (Extent<T, D>, Position<T, D>)) -> Self {
61 Self::new(from.1, from.0)
62 }
63}