chiark / gitweb /
break out svg_rectangle_path
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Sep 2020 19:44:33 +0000 (20:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Sep 2020 19:44:33 +0000 (20:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/pieces.rs

index f313cbeea4efc5880199d479edce7d0779493190..cc0e1e346c974a5a295b7f79477ef04490ee76eb 100644 (file)
@@ -99,6 +99,13 @@ pub fn svg_circle_path(diam: f64) -> Html {
   let path = svg_rescale_path(&unit_path, scale)?;
   path
 }
+
+#[throws(SE)]
+pub fn svg_rectangle_path(x: f64, y: f64) -> Html {
+  Html(format!("M {} {} h {} v {} h {} z",
+               -x*0.5, -y*0.5, x, y, -x))
+}
+
 #[typetag::serde]
 impl Outline for SimpleShape {
   #[throws(IE)]
@@ -176,8 +183,7 @@ impl PieceSpec for piece_specs::Square {
       [x, y] => (x,y),
       _ => throw!(SpecError::ImproperSizeSpec),
     };
-    let path = Html(format!("M {} {} h {} v {} h {} z",
-                            -(x as f64)*0.5, -(y as f64)*0.5, x, y, -x));
+    let path = svg_rectangle_path(x as f64, y as f64)?;
     let itemname = self.itemname.clone()
       .unwrap_or_else(||"simple-square".to_string());
     SimpleShape::new_from_path(Html::lit("square"), path, (x+y+1)/2,