1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub struct PhysicUnit;
5
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct LogicUnit;
10
11pub type Rect<T = f32> = euclid::Rect<T, LogicUnit>;
12pub type Point<T = f32> = euclid::Point2D<T, LogicUnit>;
13pub type Size<T = f32> = euclid::Size2D<T, LogicUnit>;
14pub type Transform<T = f32> = euclid::Transform2D<T, LogicUnit, LogicUnit>;
15pub type Vector<T = f32> = euclid::Vector2D<T, LogicUnit>;
16pub type Angle<T = f32> = euclid::Angle<T>;
17pub type Box2D<T = f32> = euclid::Box2D<T, LogicUnit>;
18
19pub type DeviceRect<T = i32> = euclid::Rect<T, PhysicUnit>;
20pub type DevicePoint<T = i32> = euclid::Point2D<T, PhysicUnit>;
21pub type DeviceSize<T = i32> = euclid::Size2D<T, PhysicUnit>;
22pub type DeviceVector<T = i32> = euclid::Vector2D<T, PhysicUnit>;
23
24pub const INFINITY_SIZE: Size = Size::new(f32::INFINITY, f32::INFINITY);
25pub const ZERO_SIZE: Size = Size::new(0., 0.);
26use std::ops::Add;
27
28pub use euclid::{num::Zero, rect};
29
30pub fn rect_corners<T, U>(rect: &euclid::Rect<T, U>) -> [euclid::Point2D<T, U>; 4]
33where
34 T: Copy + Add<Output = T>,
35{
36 use euclid::Point2D;
37
38 [
39 rect.min(),
40 Point2D::new(rect.max_x(), rect.min_y()),
41 rect.max(),
42 Point2D::new(rect.min_x(), rect.max_y()),
43 ]
44}
45
46pub fn transform_to_device_rect(rect: &Rect, matrix: &Transform) -> DeviceRect {
48 matrix
49 .outer_transformed_rect(rect)
50 .round_out()
51 .to_i32()
52 .cast_unit()
53}