chiark / gitweb /
make bbox_approx faillible
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Feb 2021 18:12:10 +0000 (18:12 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 01:04:41 +0000 (01:04 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bin/otterlib.rs
src/gamestate.rs
src/hand.rs
src/pieces.rs
src/shapelib.rs

index 2a1d5ac7c58d9860d228ec68aa0fe61d4e85c9fa..2eafdb33cd2afbb37807aa4023b1429d09d33844 100644 (file)
@@ -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
index 34ed47f7205a316cbeb61c37e4f20a054440961a..708189f22780d3decd11e8f50991df8ceab5427f 100644 (file)
@@ -99,7 +99,7 @@ fn preview(items: Vec<ItemForOutput>) {
       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::<Vec<_>>())
index e1e75f90ff846b78102a15c700b7500fd36bb877..6539f38149e09acb49a3cb0fd848e7bbfcbb934f 100644 (file)
@@ -119,7 +119,7 @@ pub trait Outline: Send + Debug {
   }
   fn thresh_dragraise(&self, pri: &PieceRenderInstructions)
                       -> Result<Option<Coord>, IE>;
-  fn bbox_approx(&self) -> [Pos;2];
+  fn bbox_approx(&self) -> Result<[Pos;2], IE>;
 }
 
 #[derive(Debug,Copy,Clone,Serialize,Deserialize)]
index da4038f4394ea4f9f879c4e28ca8417d20c9b50b..bb75214c67f608cd7065399a7f478f65495a852b 100644 (file)
@@ -34,7 +34,7 @@ impl Outline for Hand {
                        -> Result<Html,IE>;
       fn thresh_dragraise(&self, _pri: &PieceRenderInstructions)
                           -> Result<Option<Coord>,IE>;
-      fn bbox_approx(&self) -> [Pos;2];
+      fn bbox_approx(&self) -> Result<[Pos;2], IE>;
     }
   }
 }
index 2f11d0374df5a9a540b4708c2c08bd3ec089448d..b7f99a2bbf4885e46bdf91922a3d364ee2ed1bdb 100644 (file)
@@ -121,7 +121,7 @@ impl<Desc, Outl> Outline for GenericSimpleShape<Desc, Outl>
                        -> Result<Html,IE>;
       fn thresh_dragraise(&self, _pri: &PieceRenderInstructions)
                           -> Result<Option<Coord>,IE>;
-      fn bbox_approx(&self) -> [Pos;2];
+      fn bbox_approx(&self) -> Result<[Pos;2], IE>;
     }
   }
 }
index 97fb1ed898c27f9e1ba14106c81659655f97c172..c27b65cfe3b63176cafdcbea26adf6685a2391a8 100644 (file)
@@ -147,7 +147,7 @@ impl Outline for Item { delegate! { to self.outline {
                   -> Result<Html, IE>;
   fn thresh_dragraise(&self, pri: &PieceRenderInstructions)
                       -> Result<Option<Coord>, 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<Coord> {
     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