Skip to main content

traaains/utils/
mod.rs

1//! Collection of miscellaneous things that didn't fit anywhere else.
2
3use bevy::mesh::Mesh;
4
5pub mod alloc_map;
6pub mod interval_tree;
7pub mod linked_list;
8
9/// Abstract concept of direction of movement, whether linear or rotational.
10/// Used in `TrackPos` to determine whether a train is moving towards the "start" or the "end" node of the segment.
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12#[repr(u8)]
13pub enum Dir {
14    Positive,
15    Negative,
16}
17
18impl Dir {
19    pub fn reverse(&self) -> Self {
20        match self {
21            Dir::Positive => Dir::Negative,
22            Dir::Negative => Dir::Positive,
23        }
24    }
25
26    pub fn sig_f32(&self) -> f32 {
27        match self {
28            Dir::Positive => 1.0,
29            Dir::Negative => -1.0,
30        }
31    }
32}
33
34/// Trait for objects able to return a mesh.
35pub trait Meshable {
36    /// Props that can come in handy when generating the mesh.
37    type Props;
38
39    fn mesh(&self, props: Self::Props) -> Mesh;
40}