From: Ian Jackson Date: Sun, 21 Feb 2021 18:12:10 +0000 (+0000) Subject: make bbox_approx faillible X-Git-Tag: otter-0.4.0~334 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c8105095bf6421fb3169e631c6b823bc0719de74;p=otter.git make bbox_approx faillible Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 2a1d5ac7..2eafdb33 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -381,7 +381,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( if let Some(pinfo) = ig.ipieces.get(piece); let desc_html = pinfo.describe_html_infallible(None, p); let itemname = pinfo.itemname().to_string(); - let bbox = pinfo.bbox_approx(); + let bbox = pinfo.bbox_approx()?; let visible = if ! piece_at_all_occluded(&ig.gs.occults, piece) { Some(MgmtGamePieceVisibleInfo { pos, face, desc_html, bbox diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 34ed47f7..708189f2 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -99,7 +99,7 @@ fn preview(items: Vec) { let spec = spec.clone(); let bbox = pc - .bbox_approx(); + .bbox_approx()?; let mut bbox = bbox .iter() .map(|PosC(xy)| xy.iter().map(|&p| p as f64).collect::>()) diff --git a/src/gamestate.rs b/src/gamestate.rs index e1e75f90..6539f381 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -119,7 +119,7 @@ pub trait Outline: Send + Debug { } fn thresh_dragraise(&self, pri: &PieceRenderInstructions) -> Result, IE>; - fn bbox_approx(&self) -> [Pos;2]; + fn bbox_approx(&self) -> Result<[Pos;2], IE>; } #[derive(Debug,Copy,Clone,Serialize,Deserialize)] diff --git a/src/hand.rs b/src/hand.rs index da4038f4..bb75214c 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -34,7 +34,7 @@ impl Outline for Hand { -> Result; fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) -> Result,IE>; - fn bbox_approx(&self) -> [Pos;2]; + fn bbox_approx(&self) -> Result<[Pos;2], IE>; } } } diff --git a/src/pieces.rs b/src/pieces.rs index 2f11d037..b7f99a2b 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -121,7 +121,7 @@ impl Outline for GenericSimpleShape -> Result; fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) -> Result,IE>; - fn bbox_approx(&self) -> [Pos;2]; + fn bbox_approx(&self) -> Result<[Pos;2], IE>; } } } diff --git a/src/shapelib.rs b/src/shapelib.rs index 97fb1ed8..c27b65cf 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -147,7 +147,7 @@ impl Outline for Item { delegate! { to self.outline { -> Result; fn thresh_dragraise(&self, pri: &PieceRenderInstructions) -> Result, IE>; - fn bbox_approx(&self) -> [Pos; 2]; + fn bbox_approx(&self) -> Result<[Pos; 2], IE>; }}} #[typetag::serde(name="Lib")] @@ -262,7 +262,7 @@ impl Contents { e@ Err(_) => e?, Ok(r) => r, }; - let f0bbox = loaded.bbox_approx(); + let f0bbox = loaded.bbox_approx()?; let ier = ItemEnquiryData { itemname: k.clone(), f0bbox, @@ -505,6 +505,7 @@ impl Outline for Circle { fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) -> Option { Some((self.diam * 0.5) as Coord) } + #[throws(IE)] fn bbox_approx(&self) -> [Pos;2] { let d = (self.diam * 0.5).ceil() as Coord; [PosC([-d,-d]), PosC([d, d])] @@ -550,6 +551,7 @@ impl Outline for Rectangle { .map(OrderedFloat::from).min().unwrap().into(); Some((smallest * 0.5) as Coord) } + #[throws(IE)] fn bbox_approx(&self) -> [Pos;2] { let pos: Pos = self.xy.map( |v| ((v * 0.5).ceil()) as Coord