// centerTheData prepares the value "centered_position" found in the font shader
// as named, the function centers the text around the orthographic center of the screen
// expected to only be called within SetString
484233
func (t *Text) centerTheData(lowerLeft gltext.Point) (err error) {
	length := len(t.vboData)
	for index := 0; index < length; {
		// index (0,0)
		t.vboData[index] += lowerLeft.X
		index++
		t.vboData[index] += lowerLeft.Y
		index += 3 // skip texture data

		// index (1,0)
		t.vboData[index] += lowerLeft.X
		index++
		t.vboData[index] += lowerLeft.Y
		index += 3

		// index (1,1)
		t.vboData[index] += lowerLeft.X
		index++
		t.vboData[index] += lowerLeft.Y
		index += 3

		// index (0,1)
		t.vboData[index] += lowerLeft.X
		index++
		t.vboData[index] += lowerLeft.Y
		index += 3
	}

	// update bounding box so that it is centered around (0,0)
	t.X1.X += lowerLeft.X
	t.X2.X += lowerLeft.X
	t.X1.Y += lowerLeft.Y
	t.X2.Y += lowerLeft.Y

	// prepare objects for drawing the bounding box
	if gltext.IsDebug {
		t.BoundingBox, err = loadBoundingBox(t.Font, t.X1, t.X2)
	}
	return
}
289641
func VtctldTablet(aliasName string) template.HTML {
	return MakeVtctldRedirect(aliasName, map[string]string{
		"type":  "tablet",
		"alias": aliasName,
	})
}
396997
func (rgc *RasterGraphicContext) GetStringBounds(s string) (left, top, right, bottom float64, err error) {
	f := rgc.GetFont()
	if f == nil {
		err = errors.New("No font loaded, cannot continue")
		return
	}
	rgc.recalc()

	left = math.MaxFloat64
	top = math.MaxFloat64

	cursor := 0.0
	prev, hasPrev := truetype.Index(0), false
	for _, rc := range s {
		index := f.Index(rc)
		if hasPrev {
			cursor += fUnitsToFloat64(f.Kern(fixed.Int26_6(rgc.current.Scale), prev, index))
		}

		if err = rgc.glyphBuf.Load(rgc.current.Font, fixed.Int26_6(rgc.current.Scale), index, font.HintingNone); err != nil {
			return
		}
		e0 := 0
		for _, e1 := range rgc.glyphBuf.Ends {
			ps := rgc.glyphBuf.Points[e0:e1]
			for _, p := range ps {
				x, y := pointToF64Point(p)
				top = math.Min(top, y)
				bottom = math.Max(bottom, y)
				left = math.Min(left, x+cursor)
				right = math.Max(right, x+cursor)
			}
			e0 = e1
		}
		cursor += fUnitsToFloat64(f.HMetric(fixed.Int26_6(rgc.current.Scale), index).AdvanceWidth)
		prev, hasPrev = index, true
	}
	return
}
497837
func (js *JSONConfig) ParseData(data []byte) (Configer, error) {
	x := &JSONConfigContainer{
		data: make(map[string]interface{}),
	}
	err := json.Unmarshal(data, &x.data)
	if err != nil {
		var wrappingArray []interface{}
		err2 := json.Unmarshal(data, &wrappingArray)
		if err2 != nil {
			return nil, err
		}
		x.data["rootArray"] = wrappingArray
	}
	return x, nil
}
63324
func CapFromCenterHeight(center Point, height float64) Cap {
	return Cap{
		center: Point{center.Normalize()},
		height: height,
	}
}
297127
func (fontFace *ToyFontFace) GetSlant() FontSlant {
	ret := FontSlant(C.cairo_toy_font_face_get_slant(fontFace.Ptr))
	if err := fontFace.status(); err != nil {
		panic(err)
	}
	return ret
}
1245823
func Center(width, height int, p tview.Primitive) tview.Primitive {
	return tview.NewFlex().
		AddItem(tview.NewBox(), 0, 1, false).
		AddItem(tview.NewFlex().
			SetDirection(tview.FlexRow).
			AddItem(tview.NewBox(), 0, 1, false).
			AddItem(p, height, 1, true).
			AddItem(tview.NewBox(), 0, 1, false), width, 1, true).
		AddItem(tview.NewBox(), 0, 1, false)
}
107556
func (b Bound) Center() Point {
	return Point{
		(b.Min[0] + b.Max[0]) / 2.0,
		(b.Min[1] + b.Max[1]) / 2.0,
	}
}
1161802
func (calc *AreaCentroidCalculator) addLinearSegments(pts []float64) {
	stride := calc.stride
	for i := 0; i < len(pts)-stride; i += stride {
		segmentLen := internal.Distance2D(geom.Coord(pts[i:i+2]), pts[i+stride:i+stride+2])
		calc.totalLength += segmentLen

		midx := (pts[i] + pts[i+stride]) / 2
		calc.centSum[0] += segmentLen * midx
		midy := (pts[i+1] + pts[i+stride+1]) / 2
		calc.centSum[1] += segmentLen * midy
	}
}
1253624
func (p *JSONFormat) TransformData(data interface{}) (string, error) {
	var buf bytes.Buffer
	enc := codec.NewEncoder(&buf, jsonHandlePretty)
	err := enc.Encode(data)
	if err != nil {
		return "", err
	}

	return buf.String(), nil
}
1284107
func (t *Text) SetPosition(v mgl32.Vec2) {
	// transform to orthographic coordinates ranged -1 to 1 for the shader
	t.finalPosition[0] = v.X() / (t.Font.WindowWidth / 2)
	t.finalPosition[1] = v.Y() / (t.Font.WindowHeight / 2)
	if gltext.IsDebug {
		t.BoundingBox.finalPosition[0] = v.X() / (t.Font.WindowWidth / 2)
		t.BoundingBox.finalPosition[1] = v.Y() / (t.Font.WindowHeight / 2)
	}
	t.Position = v
}
1066037
func (rgc *RasterGraphicContext) FillStringAt(text string, x, y float64) (cursor float64, err error) {
	cursor, err = rgc.CreateStringPath(text, x, y)
	rgc.Fill()
	return
}
894020
func PointsCentroidFlat(layout geom.Layout, pointData []float64) geom.Coord {
	calc := NewPointCentroidCalculator()

	coord := geom.Coord{0, 0}
	stride := layout.Stride()
	arrayLen := len(pointData)
	for i := 0; i < arrayLen; i += stride {
		coord[0] = pointData[i]
		coord[1] = pointData[i+1]
		calc.AddCoord(coord)
	}

	return calc.GetCentroid()
}
1001342
func (a Affine) CenterFit(dst, src image.Rectangle) Affine {
	dx := float64(dst.Min.X) + float64(dst.Dx())/2
	dy := float64(dst.Min.Y) + float64(dst.Dy())/2
	sx := float64(src.Min.X) + float64(src.Dx())/2
	sy := float64(src.Min.Y) + float64(src.Dy())/2
	return I.Translate(-sx, -sy).Mul(a).Translate(dx, dy)
}
1185893
func MakeTrianglesData(len int) *TrianglesData {
	td := make(TrianglesData, len)
	for i := 0; i < len; i++ {
		td[i] = zeroValueTriangleData
	}
	return &td
}
479713
func formatData(value interface{}) (formatted interface{}) {
	switch value := value.(type) {
	case json.Marshaler:
		return value
	case error:
		return value.Error()
	case fmt.Stringer:
		return value.String()
	default:
		return value
	}
}
148749
func (c *HistChart) AddDataInt(name string, data []int, style Style) {
	fdata := make([]float64, len(data))
	for i, d := range data {
		fdata[i] = float64(d)
	}
	c.AddData(name, fdata, style)
}