From: Ian Jackson Date: Sun, 27 Sep 2020 03:01:14 +0000 (+0100) Subject: wip bbox_approx X-Git-Tag: otter-0.2.0~865 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=587146dad6a057f3b239d30ba45e828c2a8e6dd4;p=otter.git wip bbox_approx Signed-off-by: Ian Jackson --- diff --git a/src/gamestate.rs b/src/gamestate.rs index 54231352..a16b6e83 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -85,6 +85,7 @@ pub trait Outline : Send + Debug { fn surround_path(&self, pri : &PieceRenderInstructions) -> Result; fn thresh_dragraise(&self, pri : &PieceRenderInstructions) -> Result, IE>; + fn bbox_approx(&self) -> [Pos;2]; } #[typetag::serde] diff --git a/src/pieces.rs b/src/pieces.rs index 9a28cb4e..95076f4a 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -113,6 +113,7 @@ impl Outline for SimpleShape { -> Result; fn thresh_dragraise(&self, _pri : &PieceRenderInstructions) -> Result,IE>; + fn bbox_approx(&self) -> [Pos;2]; } } } diff --git a/src/shapelib.rs b/src/shapelib.rs index 0e0aa88d..eeec5316 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -139,11 +139,19 @@ struct Item { outline: Box, } +#[derive(Debug,Clone,Serialize,Deserialize)] +struct ItemEnquiryResult { + pub itemname: String, + pub bbbox: [Pos; 2], + pub f0desc: Html, +} + #[typetag::serde(name="Lib")] impl Outline for Item { delegate! { to self.outline { fn surround_path(&self, pri : &PieceRenderInstructions) -> Result; fn thresh_dragraise(&self, pri : &PieceRenderInstructions) -> Result, IE>; + fn bbox_approx(&self) -> [Pos; 2]; }}} #[typetag::serde(name="Lib")] @@ -407,6 +415,10 @@ impl Outline for Circle { -> Option { Some((self.diam * 0.5) as Coord) } + fn bbox_approx(&self) -> [Pos;2] { + let d = (self.diam * 0.5).ceil() as Coord; + [[-d,-d], [d, d]] + } } #[derive(Deserialize,Debug)] @@ -451,6 +463,15 @@ impl Outline for Square { .map(OrderedFloat::from).min().unwrap().into(); Some((smallest * 0.5) as Coord) } + fn bbox_approx(&self) -> [Pos;2] { + let pos : Pos = self.xy.iter().map( + |v| ((v * 0.5).ceil()) as Coord + ).collect::>().into_inner().unwrap(); + let neg : Pos = pos.iter().map( + |v| -v + ).collect::>().into_inner().unwrap(); + [ neg, pos ] + } } #[derive(Deserialize,Debug)]