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
use std::time::Duration;
use vecmath;
use vecmath::mat2x3_inv as inv;
use vecmath::row_mat2x3_transform_pos2 as transform_pos;
pub type Scalar = f64;
pub type Matrix2d<T = Scalar> = vecmath::Matrix2x3<T>;
pub type Rectangle<T = Scalar> = [T; 4];
pub type Vec2d<T = Scalar> = vecmath::Vector2<T>;
pub fn is_inside(pos: Vec2d, transform: Matrix2d, rect: Rectangle) -> bool {
let inv = inv(transform);
let pos = transform_pos(inv, pos);
pos[0] >= rect[0] && pos[1] >= rect[1] && pos[0] < rect[0] + rect[2] &&
pos[1] < rect[1] + rect[3]
}
pub fn duration_to_secs(duration: &Duration) -> f64 {
duration.as_secs() as f64 * 1.0e9 + duration.subsec_nanos() as f64 / 1.0e9
}