From 1b74709966aa7204cf9f67bba01e6457f0b55ade Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 10 May 2022 20:44:25 +0100 Subject: [PATCH] mformat 2: Provide OutlineDefn::load which takes an explicit size For circles we no longer insist on width and height being equal (in fact, insist on only being provided with one number), as we did for mformat 1. Rather we use the maximum of the two dimensions, for both. As documented. Signed-off-by: Ian Jackson --- src/shapelib.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/shapelib.rs b/src/shapelib.rs index 5925189d..1b83d1db 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -38,6 +38,10 @@ pub trait OutlineDefn: Debug + Sync + Send + 'static { /// 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, size: PosC) -> Outline { + RectShape { xy: size }.into() + } + fn load_mf1(&self, lgi: &GroupData, svg_sz: PosC) -> Result; } @@ -721,12 +725,15 @@ impl OutlineTrait for RectShape { struct RectDefn { } #[typetag::deserialize(name="Rect")] impl OutlineDefn for RectDefn { + fn load(&self, size: PosC) -> Outline { + RectShape { xy: size }.into() + } + #[throws(LibraryLoadError)] 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() + let size = resolve_square_size(&group.d.size)? + .ok_or_else(|| group.mformat.incompat(LLMI::SizeRequired))?; + self.load(size) } } @@ -756,6 +763,17 @@ impl OutlineTrait for CircleShape { struct CircleDefn { } #[typetag::deserialize(name="Circle")] impl OutlineDefn for CircleDefn { + fn load(&self, size: PosC) -> Outline { + let diam = size + .coords.into_iter() + .map(OrderedFloat) + .max().unwrap(). + into_inner(); + CircleShape { + diam, + }.into() + } + #[throws(LibraryLoadError)] fn load_mf1(&self, group: &GroupData, _svg_sz: PosC) -> Outline { let diam = match group.d.size.as_slice() { -- 2.30.2