chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Oct 2022 19:01:36 +0000 (20:01 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Oct 2022 19:01:36 +0000 (20:01 +0100)
src/bin/vertices.rs
src/lib.rs

index a60c8e814654e7e3509172d6daac7259d2233cf2..5492a1fafd826ed1f3e9435ab82f645e763c81e7 100644 (file)
@@ -2,15 +2,8 @@
 use z3_treefoil::*;
 
 fn main() -> io::Result<()> {
-  let mut o = io::stdout().lock();
   for shape in read_vertices() {
-    for vx in shape {
-      for c in vx {
-        write!(o, "{}", c)?;
-      }
-      write!(o, ",")?;
-    }
-    write!(o, "\n")?;
+    print_shape(&shape)?;
   }
 
   Ok(())
index 07f20b17cf54a7e5c7f05e7b21d5266b05a8d7dd..87a9c4790f77f9959e97a7267d37bee95b6b36f8 100644 (file)
@@ -8,8 +8,9 @@ pub fn default<T: Default>() -> T { Default::default() }
 pub const DIM: usize = 3;
 pub type Coord = i8;
 pub type Point = [Coord; DIM];
+pub type Shape = Vec<Point>;
 
-pub fn read_vertices() -> impl Iterator<Item=Vec<Point>> {
+pub fn read_vertices() -> impl Iterator<Item=Shape> {
   io::stdin().lines().map(|l| {
     let l = l.unwrap();
     let mut current: Point = default();
@@ -22,3 +23,15 @@ pub fn read_vertices() -> impl Iterator<Item=Vec<Point>> {
     }).collect()
   })
 }
+
+pub fn print_shape(shape: &Shape) -> io::Result<()> {
+  let mut o = io::stdout().lock();
+  for vx in shape {
+    for c in vx {
+      write!(o, "{}", c)?;
+    }
+    write!(o, ",")?;
+  }
+  write!(o, "\n")?;
+  Ok(())
+}