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 {