chiark / gitweb /
shapelib: outlines: Fold get* into load_mf1
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 May 2022 19:37:12 +0000 (20:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 May 2022 23:19:17 +0000 (00:19 +0100)
Now that we are doing checking by loading with a dummy size, and the
separate check methods are gone, the get_mf1 and get_size functions
each only have one call site.

Removing them makes the code simpler.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/shapelib.rs

index 3eae365881f220851ad0f413efbb37630a2e8ae3..5925189d6c5a40593357536d48b472393776d2f1 100644 (file)
@@ -722,17 +722,11 @@ struct RectDefn { }
 #[typetag::deserialize(name="Rect")]
 impl OutlineDefn for RectDefn {
   #[throws(LibraryLoadError)]
-  fn load_mf1(&self, lgd: &GroupData, _svg_sz: PosC<f64>) -> Outline {
-    Self::get_mf1(lgd)?.into()
-  }
-}
-impl RectDefn {
-  #[throws(LibraryLoadError)]
-  fn get_mf1(group: &GroupData) -> RectShape {
+  fn load_mf1(&self, group: &GroupData, _svg_sz: PosC<f64>) -> Outline {
     RectShape {
       xy: resolve_square_size(&group.d.size)?
         .ok_or_else(|| group.mformat.incompat(LLMI::SizeRequired))?
-    }
+    }.into()
   }
 }
 
@@ -763,20 +757,15 @@ struct CircleDefn { }
 #[typetag::deserialize(name="Circle")]
 impl OutlineDefn for CircleDefn {
   #[throws(LibraryLoadError)]
-  fn load_mf1(&self, lgd: &GroupData, _svg_sz: PosC<f64>) -> Outline {
-    CircleShape {
-      diam: Self::get_size(lgd)?,
-    }.into()
-  }
-}
-impl CircleDefn {
-  #[throws(LibraryLoadError)]
-  fn get_size(group: &GroupData) -> f64 {
-    match group.d.size.as_slice() {
+  fn load_mf1(&self, group: &GroupData, _svg_sz: PosC<f64>) -> Outline {
+    let diam = match group.d.size.as_slice() {
       &[c] => c,
       size => throw!(LLE::WrongNumberOfSizeDimensions
                      { got: size.len(), expected: [1,1] }),
-    }
+    };
+    CircleShape {
+      diam,
+    }.into()
   }
 }