chiark / gitweb /
shapelib: Implement check() as load() with dummy size
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 May 2022 11:13:25 +0000 (12:13 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 May 2022 22:18:07 +0000 (23:18 +0100)
We really want to know that we will be able to call load().  The
purpose is early detection of errors.

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

index d0bafa4828620d9a51a5ab349452b091260b2f7f..c6f8f0f185ed43af9eac4b26a0bfff812d07a599 100644 (file)
@@ -33,7 +33,11 @@ pub struct GroupData {
 
 #[typetag::deserialize(tag="outline")]
 pub trait OutlineDefn: Debug + Sync + Send + 'static {
-  fn check(&self, lgi: &GroupData) -> Result<ShapeCalculable,LLE>;
+  /// Success or failure must not depend on `svg_sz`
+  ///
+  /// Called to *check* the group configuration before load, but
+  /// with a dummy svg_gz of [1,1].  That must correctly predict
+  /// success with other sizes.
   fn load(&self, lgi: &GroupData, svg_sz: PosC<f64>) -> Result<Outline,LLE>;
 }
 #[derive(Debug,Clone,Copy)]
@@ -621,8 +625,12 @@ impl ShapeCalculable {
 impl GroupData {
   #[throws(LibraryLoadError)]
   fn check_shape(&self) -> ShapeCalculable {
-    self.d.outline.check(self)?
+    let _ = self.load_shape(PosC::new(
+      1.,1. /* dummy value, suffices for error check */
+    ))?;
+    ShapeCalculable{}
   }
+
   #[throws(LibraryLoadError)]
   fn load_shape(&self, svg_sz: PosC<f64>) -> (FaceTransform, Outline) {
     let xform = FaceTransform::from_group(&self.d)?;
@@ -687,10 +695,6 @@ impl OutlineTrait for RectShape {
 struct RectDefn { }
 #[typetag::deserialize(name="Rect")]
 impl OutlineDefn for RectDefn {
-  #[throws(LibraryLoadError)]
-  fn check(&self, lgd: &GroupData) -> ShapeCalculable {
-    Self::get(lgd).map(|_| ShapeCalculable{})?
-  }
   #[throws(LibraryLoadError)]
   fn load(&self, lgd: &GroupData, _svg_sz: PosC<f64>) -> Outline {
     Self::get(lgd)?.into()
@@ -729,10 +733,6 @@ impl OutlineTrait for CircleShape {
 struct CircleDefn { }
 #[typetag::deserialize(name="Circle")]
 impl OutlineDefn for CircleDefn {
-  #[throws(LibraryLoadError)]
-  fn check(&self, lgd: &GroupData) -> ShapeCalculable {
-    Self::get_size(lgd).map(|_| ShapeCalculable{})?
-  }
   #[throws(LibraryLoadError)]
   fn load(&self, lgd: &GroupData, _svg_sz: PosC<f64>) -> Outline {
     CircleShape {