From f119d582e02b9365876bd2cfd9508fb7a3189a44 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Wed, 15 Nov 2023 18:07:28 -0800 Subject: [PATCH] fix shape circle functions --- lib/shape/shape_circle.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/shape/shape_circle.go b/lib/shape/shape_circle.go index 72526eecb..f009b0fc8 100644 --- a/lib/shape/shape_circle.go +++ b/lib/shape/shape_circle.go @@ -37,12 +37,19 @@ func (s shapeCircle) AspectRatio1() bool { } func (s shapeCircle) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { - diameter := math.Ceil(math.Sqrt(math.Pow(width+paddingX, 2) + math.Pow(height+paddingY, 2))) + length := math.Max(width+paddingX, height+paddingY) + diameter := math.Ceil(math.Sqrt2 * length) return diameter, diameter } func (s shapeCircle) GetInsidePlacement(width, height, paddingX, paddingY float64) geo.Point { - return *geo.NewPoint(s.Box.TopLeft.X+math.Ceil(s.Box.Width/2-width/2), s.Box.TopLeft.Y+math.Ceil(s.Box.Height/2-height/2)) + project45 := 1 / math.Sqrt2 + r := s.Box.Width / 2 + // we want to offset r-padding/2 away from the center + 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)), + } } func (s shapeCircle) Perimeter() []geo.Intersectable {