From: Ian Jackson Date: Sun, 8 May 2022 11:13:25 +0000 (+0100) Subject: shapelib: Implement check() as load() with dummy size X-Git-Tag: otter-1.1.0~251 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8931e82b473da622a294c8550926453adfae150d;p=otter.git shapelib: Implement check() as load() with dummy size 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 --- diff --git a/src/shapelib.rs b/src/shapelib.rs index d0bafa48..c6f8f0f1 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -33,7 +33,11 @@ pub struct GroupData { #[typetag::deserialize(tag="outline")] pub trait OutlineDefn: Debug + Sync + Send + 'static { - fn check(&self, lgi: &GroupData) -> Result; + /// 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) -> Result; } #[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) -> (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) -> 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) -> Outline { CircleShape {