rx/
util.rs

1use rgx::core::Rect;
2use rgx::math::Point2;
3
4pub fn clamp(p: &mut Point2<i32>, rect: Rect<i32>) {
5    if p.x < rect.x1 {
6        p.x = rect.x1;
7    }
8    if p.y < rect.y1 {
9        p.y = rect.y1;
10    }
11    if p.x > rect.x2 {
12        p.x = rect.x2;
13    }
14    if p.y > rect.y2 {
15        p.y = rect.y2;
16    }
17}
18
19#[macro_export]
20macro_rules! hashmap {
21    ($( $key: expr => $val: expr ),*) => {{
22         let mut map = ::std::collections::HashMap::new();
23         $( map.insert($key.to_string(), $val); )*
24         map
25    }}
26}