• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

naomijub / bevy_knossos / 13222051392

09 Feb 2025 03:39AM UTC coverage: 87.565% (-0.8%) from 88.355%
13222051392

Pull #4

github

web-flow
Merge c737cbada into a1b79c84f
Pull Request #4: feat: add A* Pathfinding capabilities

12 of 21 new or added lines in 3 files covered. (57.14%)

1 existing line in 1 file now uncovered.

838 of 957 relevant lines covered (87.57%)

1.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/src/utils/types.rs
1
use std::fmt;
2

3
use bevy::{
4
    ecs::{component::Component, system::Resource},
5
    math::{U64Vec2, U8Vec2},
6
    reflect::Reflect,
7
};
8

9
/// Basic coords type
10
pub type Coords = (usize, usize);
11

12
/// Auxiliary Bevy component to hold Coords
13
#[derive(Clone, Debug, PartialEq, Eq, Reflect, Component, Hash)]
14
pub struct CoordsComponent {
15
    pub(crate) coord: Coords,
16
}
17

18
impl fmt::Display for CoordsComponent {
19
    /// Writes a formatted maze into a buffer
NEW
20
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
NEW
21
        write!(f, "({},{})", self.coord.0, self.coord.1)?;
×
NEW
22
        Ok(())
×
23
    }
24
}
25

26
impl CoordsComponent {
27
    /// Creates new [`CoordsComponent`]
28
    pub const fn new(x: usize, y: usize) -> Self {
1✔
29
        Self { coord: (x, y) }
30
    }
31

32
    /// Returns `x` and `y` values for [`CoordsComponent`]
33
    pub const fn xy(&self) -> (usize, usize) {
1✔
34
        (self.coord.0, self.coord.1)
1✔
35
    }
36
}
37

38
/// Maze cell size
39
#[derive(Clone, Debug, Reflect, Resource)]
40
pub struct CellSize(pub f32);
41

42
impl From<Coords> for CoordsComponent {
43
    fn from(value: Coords) -> Self {
1✔
44
        Self { coord: value }
45
    }
46
}
47

48
impl From<CoordsComponent> for Coords {
49
    fn from(value: CoordsComponent) -> Self {
1✔
50
        (value.coord.0, value.coord.1)
51
    }
52
}
53

54
impl From<U8Vec2> for CoordsComponent {
55
    fn from(value: U8Vec2) -> Self {
1✔
56
        Self {
57
            coord: (value.x as usize, value.y as usize),
1✔
58
        }
59
    }
60
}
61

62
impl From<U64Vec2> for CoordsComponent {
63
    fn from(value: U64Vec2) -> Self {
1✔
64
        Self {
65
            coord: (value.x as usize, value.y as usize),
66
        }
67
    }
68
}
69

70
/// Auxiliary Bevy component that holds the Start Coords of Pathfinding
71
#[derive(Clone, Debug, PartialEq, Eq, Reflect, Component)]
72
pub struct Start;
73

74
/// Auxiliary Bevy component that holds the Goal Coords of Pathfinding
75
#[derive(Clone, Debug, PartialEq, Eq, Reflect, Component)]
76
pub struct Goal;
77

78
#[cfg(test)]
79
mod tests {
80
    use super::*;
81

82
    #[test]
83
    fn from_coords() {
84
        let component: CoordsComponent = (42, 42).into();
85
        let expected = CoordsComponent::new(42, 42);
86

87
        assert_eq!(component, expected);
88

89
        assert_eq!(component.xy(), (42, 42));
90
    }
91

92
    #[test]
93
    fn from_coords_component() {
94
        let component = CoordsComponent { coord: (42, 42) };
95
        let component: Coords = component.into();
96

97
        assert_eq!(component, (42, 42));
98
    }
99

100
    #[test]
101
    fn from_u8vec() {
102
        let component: CoordsComponent = U8Vec2::from_array([42, 42]).into();
103
        let expected = CoordsComponent { coord: (42, 42) };
104

105
        assert_eq!(component, expected);
106
    }
107

108
    #[test]
109
    fn from_u64vec() {
110
        let component: CoordsComponent = U64Vec2::from_array([42, 42]).into();
111
        let expected = CoordsComponent { coord: (42, 42) };
112

113
        assert_eq!(component, expected);
114
    }
115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc