chiark / gitweb /
shapelib: Reorganise shape/outline handling (2)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 May 2022 11:08:34 +0000 (12:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 9 May 2022 18:24:09 +0000 (19:24 +0100)
Centralise this in two functiosn now associated with GroupData.

Now there is one place we can put new size and outline handling.

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

index ce337a116c41a7c721e7fe1721f1fc97eece1219..23781de4f6a831b8568fb6afcb63581ae09ee8c6 100644 (file)
@@ -475,10 +475,8 @@ impl Catalogue {
       item_for_item: item_for.into(),
     })?;
 
-    let eh = shape_calculable.err_mapper();
-
-    let outline = group.d.outline.load(&group, sz).map_err(eh)?;
-    let xform = FaceTransform::from_group(&group.d).map_err(eh)?;
+    let (xform, outline) = group.load_shape(sz)
+      .map_err(shape_calculable.err_mapper())?;
 
     ImageLoaded {
       svgd: svg_data,
@@ -616,6 +614,19 @@ impl ShapeCalculable {
   }
 }
 
+impl GroupData {
+  #[throws(LibraryLoadError)]
+  fn check_shape(&self) -> ShapeCalculable {
+    self.d.outline.check(self)?
+  }
+  #[throws(LibraryLoadError)]
+  fn load_shape(&self, svg_sz: PosC<f64>) -> (FaceTransform, Outline) {
+    let xform = FaceTransform::from_group(&self.d)?;
+    let outline = self.d.outline.load(&self, svg_sz)?;
+    (xform, outline)
+  }
+}
+
 //---------- RectShape ----------
 
 #[derive(Clone,Copy,Debug,Serialize,Deserialize)]
@@ -855,7 +866,7 @@ pub fn load_catalogue(libname: &str, src: &mut dyn LibrarySource)
     // We do this here rather than in the files loop because
     //  1. we want to check it even if there are no files specified
     //  2. this is OK because the group doesn't change from here on
-    let shape_calculable = group.d.outline.check(&group)?.into();
+    let shape_calculable = group.check_shape()?.into();
 
     if [
       group.d.flip,