buffer_graphics_lib/shapes/polyline/
rendering.rs

1use crate::drawing::Renderable;
2use crate::shapes::polyline::Polyline;
3use crate::shapes::polyline::Segment::*;
4use crate::Graphics;
5use log::error;
6
7impl Renderable<Polyline> for Polyline {
8    fn render(&self, graphics: &mut Graphics) {
9        if self.segments.len() < 2 {
10            error!("Polyline only has start or is empty")
11        }
12
13        let mut last_coord = if let Start(coord) = self.segments[0] {
14            coord
15        } else {
16            error!("Polyline is invalid, missing start");
17            return;
18        };
19
20        for segment in self.segments.iter().skip(1) {
21            match segment {
22                Start(_) => error!("Polyline is invalid, second start found"),
23                LineTo(coord) => graphics.draw_line(last_coord, coord, self.color),
24                ArcAround {
25                    center,
26                    angle_start,
27                    angle_end,
28                    radius,
29                } => graphics.draw_arc(
30                    *center,
31                    *angle_start,
32                    *angle_end,
33                    *radius,
34                    false,
35                    self.color,
36                ),
37            }
38            last_coord = segment.end_coord();
39        }
40    }
41}