chiark / gitweb /
attempt at SimpleShape not serialize scaled_path
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Jul 2020 00:36:08 +0000 (01:36 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Jul 2020 00:36:08 +0000 (01:36 +0100)
not v successful, will revert

src/pieces.rs

index 12f6fb5b679dfbe0245c3add4c7b1eccd86c93f9..78dc4d41127e843d58c0a8433de4aaf6469ed29e 100644 (file)
@@ -4,14 +4,20 @@ use crate::imports::*;
 type ColourMap = IndexVec<FaceId,Colour>;
 
 #[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<SimpleShapeLoad> 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 {