Quellcode durchsuchen

Add missing display for line types

Kevin Lee vor 6 Monaten
Ursprung
Commit
f803464ca6
1 geänderte Dateien mit 37 neuen und 1 gelöschten Zeilen
  1. 37 1
      src/ezcad/objects/line.rs

+ 37 - 1
src/ezcad/objects/line.rs

@@ -27,6 +27,38 @@ pub enum LineType {
     },
 }
 
+impl Display for LineType {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            LineType::Point { _zero, point } => {
+                write!(f, "Point: {}", point)
+            }
+            LineType::Line { _zero, points } => {
+                write!(
+                    f,
+                    "Line: {}",
+                    points
+                        .iter()
+                        .map(|x| format!("{x}"))
+                        .collect::<Vec<String>>()
+                        .join(", ")
+                )
+            }
+            LineType::Bezier { _zero, points } => {
+                write!(
+                    f,
+                    "Bezier: {}",
+                    points
+                        .iter()
+                        .map(|x| format!("{x}"))
+                        .collect::<Vec<String>>()
+                        .join(", ")
+                )
+            }
+        }
+    }
+}
+
 // Custom Debug implementation to only print known fields
 #[cfg(not(feature = "default-debug"))]
 impl Debug for LineType {
@@ -77,7 +109,11 @@ pub struct Lines {
 
 impl Display for Lines {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.core)
+        write!(f, "{}", self.core)?;
+        for line in &self.lines {
+            write!(f, "\n{}", line)?;
+        }
+        Ok(())
     }
 }