button_controller/
math.rs1use std::time::Duration;
4
5use vecmath;
6use vecmath::mat2x3_inv as inv;
7use vecmath::row_mat2x3_transform_pos2 as transform_pos;
8
9pub type Scalar = f64;
11
12pub type Matrix2d<T = Scalar> = vecmath::Matrix2x3<T>;
14
15pub type Rectangle<T = Scalar> = [T; 4];
17
18pub type Vec2d<T = Scalar> = vecmath::Vector2<T>;
20
21pub fn is_inside(pos: Vec2d, transform: Matrix2d, rect: Rectangle) -> bool {
23 let inv = inv(transform);
24 let pos = transform_pos(inv, pos);
25 pos[0] >= rect[0] && pos[1] >= rect[1] && pos[0] < rect[0] + rect[2] &&
26 pos[1] < rect[1] + rect[3]
27}
28
29pub fn duration_to_secs(duration: &Duration) -> f64 {
31 duration.as_secs() as f64 * 1.0e9 + duration.subsec_nanos() as f64 / 1.0e9
32}