From 0570f5cd7e84557176e63d0b4e290ee0c47a3d31 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 30 Oct 2024 19:54:11 -0600 Subject: [PATCH] change circle fit formula --- lib/shape/shape_circle.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/shape/shape_circle.go b/lib/shape/shape_circle.go index f009b0fc8..60a36c169 100644 --- a/lib/shape/shape_circle.go +++ b/lib/shape/shape_circle.go @@ -37,18 +37,22 @@ func (s shapeCircle) AspectRatio1() bool { } func (s shapeCircle) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { - length := math.Max(width+paddingX, height+paddingY) - diameter := math.Ceil(math.Sqrt2 * length) + effectiveWidth := width + 2*paddingX + effectiveHeight := height + 2*paddingY + diameter := math.Ceil(math.Max(effectiveWidth, effectiveHeight)) return diameter, diameter } func (s shapeCircle) GetInsidePlacement(width, height, paddingX, paddingY float64) geo.Point { - project45 := 1 / math.Sqrt2 - r := s.Box.Width / 2 - // we want to offset r-padding/2 away from the center + centerX := s.Box.TopLeft.X + paddingX + centerY := s.Box.TopLeft.Y + paddingY + r := s.Box.Width / 2. + x := centerX - r + y := centerY - r + return geo.Point{ - X: s.Box.TopLeft.X + math.Ceil(r-project45*(r-paddingX/2)), - Y: s.Box.TopLeft.Y + math.Ceil(r-project45*(r-paddingY/2)), + X: math.Ceil(x), + Y: math.Ceil(y), } }