fix shape circle functions

This commit is contained in:
Gavin Nishizawa 2023-11-15 18:07:28 -08:00
parent ac273cd206
commit f119d582e0
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -37,12 +37,19 @@ func (s shapeCircle) AspectRatio1() bool {
} }
func (s shapeCircle) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { 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 return diameter, diameter
} }
func (s shapeCircle) GetInsidePlacement(width, height, paddingX, paddingY float64) geo.Point { 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 { func (s shapeCircle) Perimeter() []geo.Intersectable {