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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::time::Duration;

// Re-exports
pub use winit::event::{ModifiersState as Modifiers, MouseButton, VirtualKeyCode as Key};
pub use winit::window::Fullscreen;

// Structures
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub(crate) struct RawVertex {
    pub position: [GpuScalar; 2],
    pub color: [GpuScalar; 4],
}

unsafe impl bytemuck::Pod for RawVertex {}
unsafe impl bytemuck::Zeroable for RawVertex {}

// Common types
#[cfg(feature = "force_f32")]
pub type Scalar = f32;
#[cfg(not(feature = "force_f32"))]
pub type Scalar = f64;

pub type GpuScalar = f32;
pub type Index = u32;
pub type Color = rgb::RGBA<Scalar>;

macro_rules! define_euclid {
    ($public_type:ident, $euclid_type:ident) => {
        pub type $public_type = euclid::default::$euclid_type<Scalar>;
    };
}

define_euclid!(Point, Point2D);
define_euclid!(Rotation, Rotation2D);
define_euclid!(Size, Size2D);
define_euclid!(Transform, Transform2D);
define_euclid!(Translation, Translation2D);
define_euclid!(Vector, Vector2D);
define_euclid!(BoundingBox, Box2D);

pub type Angle = euclid::Angle<Scalar>;

pub trait ScalarDuration {
    fn as_secs_scalar(&self) -> Scalar;
}

impl ScalarDuration for Duration {
    #[cfg(feature = "force_f32")]
    fn as_secs_scalar(&self) -> Scalar {
        self.as_secs_f32()
    }

    #[cfg(not(feature = "force_f32"))]
    fn as_secs_scalar(&self) -> Scalar {
        self.as_secs_f64()
    }
}