From 6b65665b6126c65f0e6f1f0519b6759a24db3c99 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Thu, 9 Feb 2023 19:42:30 -0800 Subject: [PATCH] fix GetInsidePlacement inconsistencies --- lib/shape/shape.go | 3 ++- lib/shape/shape_oval.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/shape/shape.go b/lib/shape/shape.go index db74424b3..923cb1215 100644 --- a/lib/shape/shape.go +++ b/lib/shape/shape.go @@ -87,7 +87,8 @@ func (s baseShape) GetInnerBox() *geo.Box { } func (s baseShape) GetInsidePlacement(_, _, padding float64) geo.Point { - return *geo.NewPoint(s.Box.TopLeft.X+padding, s.Box.TopLeft.Y+padding) + innerTL := s.GetInnerBox().TopLeft + return *geo.NewPoint(innerTL.X+padding, innerTL.Y+padding) } // return the minimum shape dimensions needed to fit content (width x height) diff --git a/lib/shape/shape_oval.go b/lib/shape/shape_oval.go index 77ee82fc7..90e897fe8 100644 --- a/lib/shape/shape_oval.go +++ b/lib/shape/shape_oval.go @@ -56,8 +56,8 @@ func (s shapeOval) GetInsidePlacement(width, height, padding float64) geo.Point // r is the ellipse radius on the line between node.TopLeft and the ellipse center // see https://math.stackexchange.com/questions/432902/how-to-get-the-radius-of-an-ellipse-at-a-specific-angle-by-knowing-its-semi-majo r := rx * ry / math.Sqrt(math.Pow(rx*sin, 2)+math.Pow(ry*cos, 2)) - // we want to offset r-padding away from the center - return *geo.NewPoint(s.Box.TopLeft.X+math.Ceil(rx-cos*(r-padding)), s.Box.TopLeft.Y+math.Ceil(ry-sin*(r-padding))) + // we want to offset r-padding/2 away from the center + return *geo.NewPoint(s.Box.TopLeft.X+math.Ceil(rx-cos*(r-padding/2)), s.Box.TopLeft.Y+math.Ceil(ry-sin*(r-padding/2))) } func (s shapeOval) Perimeter() []geo.Intersectable {