fix GetInsidePlacement inconsistencies

This commit is contained in:
Gavin Nishizawa 2023-02-09 19:42:30 -08:00
parent 1594486dce
commit 6b65665b61
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 4 additions and 3 deletions

View file

@ -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)

View file

@ -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 {