From 57f36183cba645898c96114dac2c2735ff56ca2e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 10 May 2022 20:37:12 +0100 Subject: [PATCH] shapelib: outlines: Fold get* into load_mf1 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 --- src/shapelib.rs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/shapelib.rs b/src/shapelib.rs index 3eae3658..5925189d 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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) -> 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) -> 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) -> 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) -> Outline { + let diam = match group.d.size.as_slice() { &[c] => c, size => throw!(LLE::WrongNumberOfSizeDimensions { got: size.len(), expected: [1,1] }), - } + }; + CircleShape { + diam, + }.into() } } -- 2.30.2