change circle fit formula
This commit is contained in:
parent
3d3925447f
commit
0570f5cd7e
1 changed files with 11 additions and 7 deletions
|
|
@ -37,18 +37,22 @@ 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) {
|
||||||
length := math.Max(width+paddingX, height+paddingY)
|
effectiveWidth := width + 2*paddingX
|
||||||
diameter := math.Ceil(math.Sqrt2 * length)
|
effectiveHeight := height + 2*paddingY
|
||||||
|
diameter := math.Ceil(math.Max(effectiveWidth, effectiveHeight))
|
||||||
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 {
|
||||||
project45 := 1 / math.Sqrt2
|
centerX := s.Box.TopLeft.X + paddingX
|
||||||
r := s.Box.Width / 2
|
centerY := s.Box.TopLeft.Y + paddingY
|
||||||
// we want to offset r-padding/2 away from the center
|
r := s.Box.Width / 2.
|
||||||
|
x := centerX - r
|
||||||
|
y := centerY - r
|
||||||
|
|
||||||
return geo.Point{
|
return geo.Point{
|
||||||
X: s.Box.TopLeft.X + math.Ceil(r-project45*(r-paddingX/2)),
|
X: math.Ceil(x),
|
||||||
Y: s.Box.TopLeft.Y + math.Ceil(r-project45*(r-paddingY/2)),
|
Y: math.Ceil(y),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue