Browse Source

Add missing display for line types

Kevin Lee 6 months ago
parent
commit
f803464ca6
1 changed files with 37 additions and 1 deletions
  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(())
     }
 }