chiark / gitweb /
dice: Adjust circle size to be right for images which are circles
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 22:41:53 +0000 (23:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 22:56:23 +0000 (23:56 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs

index c77215f714d3a099b2474d2831637483976d4d9d..78a72d8c63013ae91361039c706aa1004b9226d5 100644 (file)
@@ -152,8 +152,16 @@ impl PieceSpec for Spec {
     if_let!{ Some((nfaces,_)) = nfaces;
              else throw!(SpecError::MultipleFacesRequired) };
 
+    let radius = image.bbox_approx()?.size()?.len()? * 0.5;
+    let radius = radius * if image.shape() == Some(Shape::Circle) {
+      // bbox_approx is the diagonal of the enclosing square
+      // go back to the circle
+      0.5f64 .sqrt()
+    } else {
+      1.0
+    };
     let radius = if (0.5 .. 1.5).contains(&self.circle_scale) {
-      image.bbox_approx()?.size()?.len()? * 0.5 * self.circle_scale
+      radius * self.circle_scale
     } else {
       throw!(SpecError::InvalidSizeScale)
     };