From: Ian Jackson Date: Sun, 15 May 2022 00:34:32 +0000 (+0100) Subject: dice: Get size right in preview by setting bbox, breaking other things X-Git-Tag: otter-1.1.0~148 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=543aeccaa52790667903841d7a702596cbb5af5c;p=otter.git dice: Get size right in preview by setting bbox, breaking other things This is wrong. Signed-off-by: Ian Jackson --- diff --git a/src/dice.rs b/src/dice.rs index 59ec135a..45de14dc 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -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; fn shape(&self) -> Option; } } diff --git a/support/imports.rs b/support/imports.rs index 60d03c72..f244656d 100644 --- a/support/imports.rs +++ b/support/imports.rs @@ -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;