From: Ian Jackson Date: Sat, 14 May 2022 22:41:53 +0000 (+0100) Subject: dice: Adjust circle size to be right for images which are circles X-Git-Tag: otter-1.1.0~153 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=cdd4531eb89ac938561b5d66118ffb6aebcfa877;p=otter.git dice: Adjust circle size to be right for images which are circles Signed-off-by: Ian Jackson --- diff --git a/src/dice.rs b/src/dice.rs index c77215f7..78a72d8c 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -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) };