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

Xevion / Pac-Man / 16584527047

29 Jul 2025 01:49AM UTC coverage: 84.893% (+79.4%) from 5.538%
16584527047

push

github

Xevion
refactor: remove StartingPosition MapTile, track pacman start explicitly in parser

23 of 23 new or added lines in 3 files covered. (100.0%)

247 existing lines in 14 files now uncovered.

2568 of 3025 relevant lines covered (84.89%)

987.28 hits per line

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

69.32
/src/map/render.rs
1
//! Map rendering functionality.
2

3
use crate::texture::sprite::{AtlasTile, SpriteAtlas};
4
use sdl2::pixels::Color;
5
use sdl2::rect::{Point, Rect};
6
use sdl2::render::{Canvas, RenderTarget};
7

8
/// Handles rendering operations for the map.
9
pub struct MapRenderer;
10

11
impl MapRenderer {
12
    /// Renders the map to the given canvas.
13
    ///
14
    /// This function draws the static map texture to the screen at the correct
15
    /// position and scale.
UNCOV
16
    pub fn render_map<T: RenderTarget>(canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, map_texture: &mut AtlasTile) {
×
17
        let dest = Rect::new(
×
UNCOV
18
            crate::constants::BOARD_PIXEL_OFFSET.x as i32,
×
19
            crate::constants::BOARD_PIXEL_OFFSET.y as i32,
×
20
            crate::constants::BOARD_PIXEL_SIZE.x,
×
21
            crate::constants::BOARD_PIXEL_SIZE.y,
×
22
        );
×
UNCOV
23
        let _ = map_texture.render(canvas, atlas, dest);
×
24
    }
×
25

26
    /// Renders a debug visualization of the navigation graph.
27
    ///
28
    /// This function is intended for development and debugging purposes. It draws the
29
    /// nodes and edges of the graph on top of the map, allowing for visual
30
    /// inspection of the navigation paths.
UNCOV
31
    pub fn debug_render_nodes<T: RenderTarget>(graph: &crate::entity::graph::Graph, canvas: &mut Canvas<T>) {
×
32
        for i in 0..graph.node_count() {
×
33
            let node = graph.get_node(i).unwrap();
×
34
            let pos = node.position + crate::constants::BOARD_PIXEL_OFFSET.as_vec2();
×
35

×
UNCOV
36
            // Draw connections
×
UNCOV
37
            canvas.set_draw_color(Color::BLUE);
×
38

UNCOV
39
            for edge in graph.adjacency_list[i].edges() {
×
40
                let end_pos = graph.get_node(edge.target).unwrap().position + crate::constants::BOARD_PIXEL_OFFSET.as_vec2();
×
41
                canvas
×
42
                    .draw_line((pos.x as i32, pos.y as i32), (end_pos.x as i32, end_pos.y as i32))
×
43
                    .unwrap();
×
UNCOV
44
            }
×
45

46
            // Draw node
47
            // let color = if pacman.position.from_node_idx() == i.into() {
48
            //     Color::GREEN
49
            // } else if let Some(to_idx) = pacman.position.to_node_idx() {
50
            //     if to_idx == i.into() {
51
            //         Color::CYAN
52
            //     } else {
53
            //         Color::RED
54
            //     }
55
            // } else {
56
            //     Color::RED
57
            // };
UNCOV
58
            canvas.set_draw_color(Color::GREEN);
×
59
            canvas
×
60
                .fill_rect(Rect::new(0, 0, 3, 3).centered_on(Point::new(pos.x as i32, pos.y as i32)))
×
61
                .unwrap();
×
62

63
            // Draw node index
64
            // text.render(canvas, atlas, &i.to_string(), pos.as_uvec2()).unwrap();
65
        }
UNCOV
66
    }
×
67
}
68

69
#[cfg(test)]
70
mod tests {
71
    use super::*;
72
    use crate::entity::graph::{Graph, Node};
73
    use crate::texture::sprite::{AtlasMapper, MapperFrame};
74
    use std::collections::HashMap;
75

76
    fn create_test_graph() -> Graph {
2✔
77
        let mut graph = Graph::new();
2✔
78
        let node1 = graph.add_node(Node {
2✔
79
            position: glam::Vec2::new(0.0, 0.0),
2✔
80
        });
2✔
81
        let node2 = graph.add_node(Node {
2✔
82
            position: glam::Vec2::new(16.0, 0.0),
2✔
83
        });
2✔
84
        let node3 = graph.add_node(Node {
2✔
85
            position: glam::Vec2::new(0.0, 16.0),
2✔
86
        });
2✔
87

2✔
88
        graph
2✔
89
            .connect(node1, node2, false, None, crate::entity::direction::Direction::Right)
2✔
90
            .unwrap();
2✔
91
        graph
2✔
92
            .connect(node1, node3, false, None, crate::entity::direction::Direction::Down)
2✔
93
            .unwrap();
2✔
94

2✔
95
        graph
2✔
96
    }
2✔
97

98
    fn create_test_atlas() -> SpriteAtlas {
2✔
99
        let mut frames = HashMap::new();
2✔
100
        frames.insert(
2✔
101
            "maze/full.png".to_string(),
2✔
102
            MapperFrame {
2✔
103
                x: 0,
2✔
104
                y: 0,
2✔
105
                width: 224,
2✔
106
                height: 248,
2✔
107
            },
2✔
108
        );
2✔
109
        let mapper = AtlasMapper { frames };
2✔
110
        let dummy_texture = unsafe { std::mem::zeroed() };
2✔
111
        SpriteAtlas::new(dummy_texture, mapper)
2✔
112
    }
2✔
113

114
    #[test]
115
    fn test_render_map_does_not_panic() {
2✔
116
        // This test just ensures the function doesn't panic
2✔
117
        // We can't easily test the actual rendering without SDL context
2✔
118
        let atlas = create_test_atlas();
2✔
119
        let _map_texture = SpriteAtlas::get_tile(&atlas, "maze/full.png").unwrap();
2✔
120

2✔
121
        // The function should not panic even with dummy data
2✔
122
        // Note: We can't actually call render_map without a canvas, but we can test the logic
2✔
123
        assert!(true); // Placeholder test
2✔
124
    }
2✔
125

126
    #[test]
127
    fn test_debug_render_nodes_does_not_panic() {
2✔
128
        // This test just ensures the function doesn't panic
2✔
129
        // We can't easily test the actual rendering without SDL context
2✔
130
        let _graph = create_test_graph();
2✔
131

2✔
132
        // The function should not panic even with dummy data
2✔
133
        // Note: We can't actually call debug_render_nodes without a canvas, but we can test the logic
2✔
134
        assert!(true); // Placeholder test
2✔
135
    }
2✔
136

137
    #[test]
138
    fn test_map_renderer_structure() {
2✔
139
        // Test that MapRenderer is a unit struct
2✔
140
        let _renderer = MapRenderer;
2✔
141
        // This should compile and not panic
2✔
142
        assert!(true);
2✔
143
    }
2✔
144
}
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