chiark / gitweb /
dice: Get size right in preview by setting bbox, breaking other things
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 00:34:32 +0000 (01:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 00:34:36 +0000 (01:34 +0100)
This is wrong.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs
support/imports.rs

index 59ec135a449919dc271ee4bc72205bbcccc8b35c..45de14dc7edcd6c0c6bddd7c2de1872f40583c31 100644 (file)
@@ -317,9 +317,37 @@ impl OutlineTrait for Die {
     self.surround_outline.outline_path(1.0)?
   }
 
+  // This is not consistent with the surround_path: the surround_path
+  // does not include the cooldown circle, but this does.  The effecti
+  // is that if the piece needs to be tiled, there is room for the circle.
+  // This happens when:
+  //
+  //  * Pieces are added with the CLI.  Presumably not many dice so
+  //    this is probably OK.  (Size is also returned via ListPieces.)
+  //  * Library preview.  Boxes for dice are big enough for the cooldown
+  //    which is shown in the preview.
+  //  * Hidden tiling etc.  Not relevant for dice, which do not Mix
+  //    in occultation.
+  //  * "Organise" function.
+  //  * Finding pieces that have been clicked on in the client.
+  //
+  // More places...
+  //
+  // bbox is also used with other non-inert pieces, eg, currency
+  // (are we merging)
+  //
+  // Because we don't get auto-rearranged during occultation, 
+  #[throws(IE)]
+  fn bbox_approx(&self) -> Rect {
+    let r: Coord = cast(self.cooldown_radius.ceil())
+      .ok_or(CoordinateOverflow)?;
+    let br = PosC::new(r,r);
+    let tl = (-br)?;
+    Rect{ corners: [tl,br] }
+  }
+
   delegate! {
     to self.surround_outline {
-      fn bbox_approx(&self) -> Result<Rect, IE>;
       fn shape(&self) -> Option<Shape>;
     }
   }
index 60d03c7214d4a5bdd9542852cd9118d1372b1bb5..f244656d47e552123540b35590a8892ad54831e2 100644 (file)
@@ -42,7 +42,7 @@ pub use nix::unistd::{self, Uid};
 pub use nix::sys::time::TimeSpec;
 pub use nix::time::clock_gettime;
 pub use num_derive::{ToPrimitive, FromPrimitive};
-pub use num_traits::{Bounded, FromPrimitive, ToPrimitive};
+pub use num_traits::{cast, Bounded, FromPrimitive, ToPrimitive};
 pub use paste::paste;
 pub use rand::distributions::Alphanumeric;
 pub use rand::thread_rng;