// Center returns the center of the box
177643
func (b Box) Center() (x, y int) {
	w2, h2 := b.Width()>>1, b.Height()>>1
	return b.Left + w2, b.Top + h2
}
813296
func (b *Box) Place(container *Box) {
	b.frame.X = container.inner.X
	b.frame.Y = container.inner.Y
}
570533
func (b Box) Width() int {
	return util.Math.AbsInt(b.Right - b.Left)
}
142168
func (bc BoxCorners) Height() int {
	minTop := util.Math.MinInt(bc.TopLeft.Y, bc.TopRight.Y)
	maxBottom := util.Math.MaxInt(bc.BottomLeft.Y, bc.BottomRight.Y)
	return maxBottom - minTop
}
726412
func LinesCentroid(line *geom.LineString, extraLines ...*geom.LineString) (centroid geom.Coord) {
	calculator := NewLineCentroidCalculator(line.Layout())
	calculator.AddLine(line)

	for _, l := range extraLines {
		calculator.AddLine(l)
	}

	return calculator.GetCentroid()
}
575813
func (w *Weavebox) Box(prefix string) *Box {
	b := &Box{*w}
	b.Weavebox.prefix += prefix
	return b
}
1189079
func (calc *AreaCentroidCalculator) GetCentroid() geom.Coord {
	cent := geom.Coord(make([]float64, calc.stride))

	if calc.centSum == nil {
		return cent
	}

	if math.Abs(calc.areasum2) > 0.0 {
		cent[0] = calc.cg3[0] / 3 / calc.areasum2
		cent[1] = calc.cg3[1] / 3 / calc.areasum2
	} else {
		// if polygon was degenerate, compute linear centroid instead
		cent[0] = calc.centSum[0] / calc.totalLength
		cent[1] = calc.centSum[1] / calc.totalLength
	}
	return cent
}
1350828
func (t *Tabulate) padCenter(width int, str string) string {
	b := createBuffer()
	padding := int(math.Ceil(float64((width - runewidth.StringWidth(str))) / 2.0))
	b.Write(" ", padding)
	b.Write(str, 1)
	b.Write(" ", (width - runewidth.StringWidth(b.String())))

	return b.String()
}
961705
func Box(src image.Image, radius float64) *image.RGBA {
	if radius <= 0 {
		return clone.AsRGBA(src)
	}

	length := int(math.Ceil(2*radius + 1))
	k := convolution.NewKernel(length, length)

	for x := 0; x < length; x++ {
		for y := 0; y < length; y++ {
			k.Matrix[y*length+x] = 1
		}
	}

	return convolution.Convolve(src, k.Normalized(), &convolution.Options{Bias: 0, Wrap: false, KeepAlpha: false})
}
1058789
func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners {
	cx, cy := bc.Center()

	thetaRadians := util.Math.DegreesToRadians(thetaDegrees)

	tlx, tly := util.Math.RotateCoordinate(cx, cy, bc.TopLeft.X, bc.TopLeft.Y, thetaRadians)
	trx, try := util.Math.RotateCoordinate(cx, cy, bc.TopRight.X, bc.TopRight.Y, thetaRadians)
	brx, bry := util.Math.RotateCoordinate(cx, cy, bc.BottomRight.X, bc.BottomRight.Y, thetaRadians)
	blx, bly := util.Math.RotateCoordinate(cx, cy, bc.BottomLeft.X, bc.BottomLeft.Y, thetaRadians)

	return BoxCorners{
		TopLeft:     Point{tlx, tly},
		TopRight:    Point{trx, try},
		BottomRight: Point{brx, bry},
		BottomLeft:  Point{blx, bly},
	}
}
1194454
func (box *Box) Intersects(other *Box) bool {
	d1 := box.Diagonal()
	d2 := other.Diagonal()
	sizes := Add(&d1, &d2)
	c1 := box.Center()
	c2 := other.Center()
	distCenters2 := Sub(&c1, &c2)
	distCenters2.Scale(2)
	distCenters2.Abs()
	return distCenters2[0] <= sizes[0] && distCenters2[1] <= sizes[1] && distCenters2[2] <= sizes[2]
}
1089824
func (c *Client) GetDatacenter(datacenterName string) (string, error) {
	var respHeader http.Header
	req := request{
		method:         client.GET,
		url:            makeURL(apiDatacenters, datacenterName),
		respHeader:     &respHeader,
		expectedStatus: http.StatusFound,
	}
	respData, err := c.sendRequest(req)
	if err != nil {
		return "", errors.Newf(err, "failed to get datacenter with name: %s", datacenterName)
	}
	return respData.RespHeaders.Get("Location"), nil
}
696694
func LinearRingsCentroid(line *geom.LinearRing, extraLines ...*geom.LinearRing) (centroid geom.Coord) {
	calculator := NewLineCentroidCalculator(line.Layout())
	calculator.AddLinearRing(line)

	for _, l := range extraLines {
		calculator.AddLinearRing(l)
	}

	return calculator.GetCentroid()
}
24026
func (s *SimpleStyledTextBar) SetCenter(m string) {
	s.initialize()
	s.center.SetMarkup(m)
}
656523
func (sbc StackedBarChart) Box() Box {
	dpr := sbc.Background.Padding.GetRight(10)
	dpb := sbc.Background.Padding.GetBottom(50)

	return Box{
		Top:    sbc.Background.Padding.GetTop(20),
		Left:   sbc.Background.Padding.GetLeft(20),
		Right:  sbc.GetWidth() - dpr,
		Bottom: sbc.GetHeight() - dpb,
	}
}
1019163
func (e *Element) getCenter() (int, int, error) {
	points, err := e.Dimensions()
	if err != nil {
		return 0, 0, err
	}

	x, y, err := centroid(points)
	if err != nil {
		return 0, 0, err
	}
	return x, y, nil
}
689271
func (pc DonutChart) Box() Box {
	dpr := pc.Background.Padding.GetRight(DefaultBackgroundPadding.Right)
	dpb := pc.Background.Padding.GetBottom(DefaultBackgroundPadding.Bottom)

	return Box{
		Top:    pc.Background.Padding.GetTop(DefaultBackgroundPadding.Top),
		Left:   pc.Background.Padding.GetLeft(DefaultBackgroundPadding.Left),
		Right:  pc.GetWidth() - dpr,
		Bottom: pc.GetHeight() - dpb,
	}
}