From 16fe7a9d7ce0b8db8329857e011ee665f4450267 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 26 Sep 2020 20:44:33 +0100 Subject: [PATCH] break out svg_rectangle_path Signed-off-by: Ian Jackson --- src/pieces.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pieces.rs b/src/pieces.rs index f313cbee..cc0e1e34 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -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, -- 2.30.2