grafix_toolbox/kit/policies/func/
range.rs1use crate::lib::*;
2
3pub trait uRange {
4 fn get_range(&self) -> ulVec2;
5}
6
7macro_rules! impl_range {
8 ($($t: ty),+) => {
9 $(impl uRange for $t {
10 #[inline(always)]
11 fn get_range(&self) -> ulVec2 {
12 range(self)
13 }
14 })+
15 }
16}
17macro_rules! impl_range_type {
18 ($($t: ty),+) => {
19 $(impl_range!(ops::Range<$t>, ops::RangeFrom<$t>, ops::RangeInclusive<$t>, ops::RangeTo<$t>, ops::RangeToInclusive<$t>);)+
20 }
21}
22impl_range_type!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize);
23
24macro_rules! impl_single {
25 ($($t: ty),+) => {
26 $(impl uRange for $t {
27 #[inline(always)]
28 fn get_range(&self) -> ulVec2 {
29 range(&(*self..*self + 1))
30 }
31 })+
32 }
33}
34impl_single!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize);
35
36impl uRange for ops::RangeFull {
37 #[inline(always)]
38 fn get_range(&self) -> ulVec2 {
39 range::<usize>(self)
40 }
41}
42
43fn range<T: Copy>(r: &impl ops::RangeBounds<T>) -> ulVec2
44where
45 usize: Cast<T>,
46{
47 use ops::Bound::{Excluded as E, Included as I, Unbounded as U};
48 (
49 match r.start_bound() {
50 U => usize::MIN,
51 I(&i) => usize(i),
52 E(&i) => usize(i) + 1,
53 },
54 match r.end_bound() {
55 U => usize::MAX,
56 I(&i) => usize(i) + 1,
57 E(&i) => usize(i),
58 },
59 )
60}