gemini_engine/primitives/
polygon.rs1use super::Triangle;
2use crate::core::{CanDraw, ColChar, Vec2D};
3
4pub struct Polygon {
8 pub vertices: Vec<Vec2D>,
10 pub fill_char: ColChar,
12}
13
14impl Polygon {
15 #[must_use]
17 pub fn new(vertices: &[Vec2D], fill_char: ColChar) -> Self {
18 Self {
19 vertices: vertices.to_vec(),
20 fill_char,
21 }
22 }
23}
24
25impl CanDraw for Polygon {
26 fn draw_to(&self, canvas: &mut impl crate::core::Canvas) {
27 super::triangulate(&self.vertices)
28 .into_iter()
29 .map(|corners| Triangle::with_array(corners, self.fill_char))
30 .for_each(|t| t.draw_to(canvas));
31 }
32}