chiark / gitweb /
wip bbox_approx
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Sep 2020 03:01:14 +0000 (04:01 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Sep 2020 03:04:27 +0000 (04:04 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/pieces.rs
src/shapelib.rs

index 54231352721226cd5d87c2fa2c6aca35f5eefbe7..a16b6e833f74463a8f71a34d0dce777898a6b87a 100644 (file)
@@ -85,6 +85,7 @@ pub trait Outline : Send + Debug {
   fn surround_path(&self, pri : &PieceRenderInstructions) -> Result<Html, IE>;
   fn thresh_dragraise(&self, pri : &PieceRenderInstructions)
                       -> Result<Option<Coord>, IE>;
+  fn bbox_approx(&self) -> [Pos;2];
 }
 
 #[typetag::serde]
index 9a28cb4ed8053e0d2f87b42d0ff61150f24a174b..95076f4ae410a9bf52fbc43c3f4ba46c8efa9570 100644 (file)
@@ -113,6 +113,7 @@ impl Outline for SimpleShape {
                        -> Result<Html,IE>;
       fn thresh_dragraise(&self, _pri : &PieceRenderInstructions)
                           -> Result<Option<Coord>,IE>;
+      fn bbox_approx(&self) -> [Pos;2];
     }
   }
 }
index 0e0aa88de1f910a52e9f62697a6357d393b11f6c..eeec5316bf62f95a8394e5ccc0472903918777c6 100644 (file)
@@ -139,11 +139,19 @@ struct Item {
   outline: Box<dyn Outline>,
 }
 
+#[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<Html, IE>;
   fn thresh_dragraise(&self, pri : &PieceRenderInstructions)
                       -> Result<Option<Coord>, IE>;
+  fn bbox_approx(&self) -> [Pos; 2];
 }}}
 
 #[typetag::serde(name="Lib")]
@@ -407,6 +415,10 @@ impl Outline for Circle {
                       -> Option<Coord> {
     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::<ArrayVec<_>>().into_inner().unwrap();
+    let neg : Pos = pos.iter().map(
+      |v| -v
+    ).collect::<ArrayVec<_>>().into_inner().unwrap();
+    [ neg, pos ]
+  }
 }
 
 #[derive(Deserialize,Debug)]