From: Ian Jackson Date: Sun, 19 Jul 2020 00:36:08 +0000 (+0100) Subject: attempt at SimpleShape not serialize scaled_path X-Git-Tag: otter-0.2.0~1290 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=db24f5da3633e69ec79b6aebab117efef3a52668;p=otter.git attempt at SimpleShape not serialize scaled_path not v successful, will revert --- diff --git a/src/pieces.rs b/src/pieces.rs index 12f6fb5b..78dc4d41 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -4,14 +4,20 @@ use crate::imports::*; type ColourMap = IndexVec; #[derive(Debug,Serialize,Deserialize)] +#[serde(try_from="SimpleShapeLoad")] struct SimpleShape { desc : String, path : String, + #[serde(skip)] scaled_path : String, approx_dia : Coord, colours : ColourMap, } +#[derive(Deserialize)] +#[serde(transparent)] +struct SimpleShapeLoad(SimpleShape); + const SELECT_SCALE : f64 = 1.1; @@ -108,14 +114,24 @@ impl Piece for SimpleShape { } } +impl TryFrom for SimpleShape { + type Error = SVGProcessingError; + #[throws(SE)] + fn try_from(l: SimpleShapeLoad) -> SimpleShape { + let mut s = l.0; + s.scaled_path = svg_rescale_path(&s.path, SELECT_SCALE)?; + s + } +} + impl SimpleShape { #[throws(SE)] fn new_from_path(desc: String, path: String, approx_dia: Coord, colours: ColourMap) -> Self { - SimpleShape { - scaled_path : svg_rescale_path(&path, SELECT_SCALE)?, + SimpleShapeLoad(SimpleShape { + scaled_path : Default::default(), desc, approx_dia, path, colours, - } + }).try_into()? } #[throws(SE)] fn new_circle(dia: Coord, colours: ColourMap) -> Self {