// makeSquareMapping finds an optimal glyph arrangement of the given runes, so that their common
// bounding box is as square as possible.
492013
func makeSquareMapping(face font.Face, runes []rune, padding fixed.Int26_6) (map[rune]fixedGlyph, fixed.Rectangle26_6) {
	width := sort.Search(int(fixed.I(1024*1024)), func(i int) bool {
		width := fixed.Int26_6(i)
		_, bounds := makeMapping(face, runes, padding, width)
		return bounds.Max.X-bounds.Min.X >= bounds.Max.Y-bounds.Min.Y
	})
	return makeMapping(face, runes, padding, fixed.Int26_6(width))
}
738558
func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align) {
	lines := dc.WordWrap(s, width)

	// sync h formula with MeasureMultilineString
	h := float64(len(lines)) * dc.fontHeight * lineSpacing
	h -= (lineSpacing - 1) * dc.fontHeight

	x -= ax * width
	y -= ay * h
	switch align {
	case AlignLeft:
		ax = 0
	case AlignCenter:
		ax = 0.5
		x += width / 2
	case AlignRight:
		ax = 1
		x += width
	}
	ay = 1
	for _, line := range lines {
		dc.DrawStringAnchored(line, x, y, ax, ay)
		y += dc.fontHeight * lineSpacing
	}
}
134718
func (f ClientMapperFunc) ClientForMapping(mapping *meta.RESTMapping) (RESTClient, error) {
	return f(mapping)
}
362700
func makeQuantiles(m *dto.Metric) map[string]interface{} {
	fields := make(map[string]interface{})
	for _, q := range m.GetSummary().Quantile {
		if !math.IsNaN(q.GetValue()) {
			fields[fmt.Sprint(q.GetQuantile())] = float64(q.GetValue())
		}
	}
	return fields
}
88541
func FlattenJsonMapIntoQs(uv url.Values, jsonMap map[string]interface{}, pre string) error {
	for k, v := range jsonMap {
		if err := flattenJsonValue(uv, v, pre+k); err != nil {
			return err
		}
	}
	return nil
}
1131412
func (wxa *MiniProgram) CreateWXAQRCode(coderParams QRCoder) (response []byte, err error) {
	return wxa.fetchCode(createWXAQRCodeURL, coderParams)
}
1175210
func MakeMagicEndpoint(magic *Magic) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(Workload)
		result, err := magic.DoMagic(req)
		return result, err
	}
}
755513
func (dm *DocumentMapping) closestDocMapping(path string) *DocumentMapping {
	pathElements := decodePath(path)
	current := dm
OUTER:
	for _, pathElement := range pathElements {
		for name, subDocMapping := range current.Properties {
			if name == pathElement {
				current = subDocMapping
				continue OUTER
			}
		}
		break
	}
	return current
}
861739
func makeQuery(t, q string, a map[string]interface{}) map[string]interface{} {
	return map[string]interface{}{
		"t": t,
		"y": "q",
		"q": q,
		"a": a,
	}
}
1271843
func (i *ImageService) MakeImageCache(sourceRefs []string) builder.ImageCache {
	if len(sourceRefs) == 0 {
		return cache.NewLocal(i.imageStore)
	}

	cache := cache.New(i.imageStore)

	for _, ref := range sourceRefs {
		img, err := i.GetImage(ref)
		if err != nil {
			logrus.Warnf("Could not look up %s for cache resolution, skipping: %+v", ref, err)
			continue
		}
		cache.Populate(img)
	}

	return cache
}
448118
func (style *Style) makeXLSXStyleElements() (xFont xlsxFont, xFill xlsxFill, xBorder xlsxBorder, xCellXf xlsxXf) {
	xFont = xlsxFont{}
	xFill = xlsxFill{}
	xBorder = xlsxBorder{}
	xCellXf = xlsxXf{}
	xFont.Sz.Val = strconv.Itoa(style.Font.Size)
	xFont.Name.Val = style.Font.Name
	xFont.Family.Val = strconv.Itoa(style.Font.Family)
	xFont.Charset.Val = strconv.Itoa(style.Font.Charset)
	xFont.Color.RGB = style.Font.Color
	if style.Font.Bold {
		xFont.B = &xlsxVal{}
	} else {
		xFont.B = nil
	}
	if style.Font.Italic {
		xFont.I = &xlsxVal{}
	} else {
		xFont.I = nil
	}
	if style.Font.Underline {
		xFont.U = &xlsxVal{}
	} else {
		xFont.U = nil
	}
	xPatternFill := xlsxPatternFill{}
	xPatternFill.PatternType = style.Fill.PatternType
	xPatternFill.FgColor.RGB = style.Fill.FgColor
	xPatternFill.BgColor.RGB = style.Fill.BgColor
	xFill.PatternFill = xPatternFill
	xBorder.Left = xlsxLine{
		Style: style.Border.Left,
		Color: xlsxColor{RGB: style.Border.LeftColor},
	}
	xBorder.Right = xlsxLine{
		Style: style.Border.Right,
		Color: xlsxColor{RGB: style.Border.RightColor},
	}
	xBorder.Top = xlsxLine{
		Style: style.Border.Top,
		Color: xlsxColor{RGB: style.Border.TopColor},
	}
	xBorder.Bottom = xlsxLine{
		Style: style.Border.Bottom,
		Color: xlsxColor{RGB: style.Border.BottomColor},
	}
	xCellXf = makeXLSXCellElement()
	xCellXf.ApplyBorder = style.ApplyBorder
	xCellXf.ApplyFill = style.ApplyFill
	xCellXf.ApplyFont = style.ApplyFont
	xCellXf.ApplyAlignment = style.ApplyAlignment
	if style.NamedStyleIndex != nil {
		xCellXf.XfId = style.NamedStyleIndex
	}
	return
}
1337089
func (er *expressionRewriter) buildQuantifierPlan(agg *Aggregation, cond, rexpr expression.Expression, all bool) {
	isNullFunc, _ := expression.NewFunction(er.ctx, ast.IsNull, types.NewFieldType(mysql.TypeTiny), rexpr.Clone())
	sumFunc := expression.NewAggFunction(ast.AggFuncSum, []expression.Expression{isNullFunc}, false)
	countFuncNull := expression.NewAggFunction(ast.AggFuncCount, []expression.Expression{isNullFunc.Clone()}, false)
	agg.AggFuncs = append(agg.AggFuncs, sumFunc, countFuncNull)
	posID := agg.schema.Len()
	aggColSum := &expression.Column{
		ColName:  model.NewCIStr("agg_col_sum"),
		FromID:   agg.id,
		Position: posID,
		RetType:  sumFunc.GetType(),
	}
	agg.schema.Append(aggColSum)
	if all {
		aggColCountNull := &expression.Column{
			ColName:  model.NewCIStr("agg_col_cnt"),
			FromID:   agg.id,
			Position: posID + 1,
			RetType:  countFuncNull.GetType(),
		}
		agg.schema.Append(aggColCountNull)
		// All of the inner record set should not contain null value. So for t.id < all(select s.id from s), it
		// should be rewrote to t.id < min(s.id) and if(sum(s.id is null) = 0, true, null).
		hasNotNull, _ := expression.NewFunction(er.ctx, ast.EQ, types.NewFieldType(mysql.TypeTiny), aggColSum.Clone(), expression.Zero)
		nullChecker, _ := expression.NewFunction(er.ctx, ast.If, types.NewFieldType(mysql.TypeTiny), hasNotNull, expression.One, expression.Null)
		cond = expression.ComposeCNFCondition(er.ctx, cond, nullChecker)
		// If the set is empty, it should always return true.
		checkEmpty, _ := expression.NewFunction(er.ctx, ast.EQ, types.NewFieldType(mysql.TypeTiny), aggColCountNull.Clone(), expression.Zero)
		cond = expression.ComposeDNFCondition(er.ctx, cond, checkEmpty)
	} else {
		// For "any" expression, if the record set has null and the cond return false, the result should be NULL.
		hasNull, _ := expression.NewFunction(er.ctx, ast.NE, types.NewFieldType(mysql.TypeTiny), aggColSum.Clone(), expression.Zero)
		nullChecker, _ := expression.NewFunction(er.ctx, ast.If, types.NewFieldType(mysql.TypeTiny), hasNull, expression.Null, expression.Zero)
		cond = expression.ComposeDNFCondition(er.ctx, cond, nullChecker)
	}
	if !er.asScalar {
		// For Semi Apply without aux column, the result is no matter false or null. So we can add it to join predicate.
		er.p = er.b.buildSemiApply(er.p, agg, []expression.Expression{cond}, false, false)
		return
	}
	// If we treat the result as a scalar value, we will add a projection with a extra column to output true, false or null.
	outerSchemaLen := er.p.GetSchema().Len()
	er.p = er.b.buildInnerApply(er.p, agg)
	joinSchema := er.p.GetSchema()
	proj := &Projection{
		baseLogicalPlan: newBaseLogicalPlan(Proj, er.b.allocator),
		Exprs:           expression.Column2Exprs(joinSchema.Clone().Columns[:outerSchemaLen]),
	}
	proj.self = proj
	proj.initIDAndContext(er.ctx)
	proj.SetSchema(expression.NewSchema(joinSchema.Clone().Columns[:outerSchemaLen]))
	proj.Exprs = append(proj.Exprs, cond)
	proj.schema.Append(&expression.Column{
		FromID:      proj.id,
		ColName:     model.NewCIStr("aux_col"),
		Position:    proj.schema.Len(),
		IsAggOrSubq: true,
		RetType:     cond.GetType(),
	})
	addChild(proj, er.p)
	er.p = proj
}
592533
func AppendQwordReg(regs []Register, name string, value uint64) []Register {
	var buf bytes.Buffer
	binary.Write(&buf, binary.LittleEndian, value)
	return append(regs, Register{name, buf.Bytes(), fmt.Sprintf("%#016x", value)})
}
1004872
func (c *ClientContext) MakeSignature(msg []byte, qop, seqno uint32) ([]byte, error) {
	return makeSignature(c.sctxt, msg, qop, seqno)
}
643522
func (p *Pattern) geoXes() {
	squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 25)
	xShape := shapes.BuildPlus(squareSize)
	xSize := squareSize * 3 * 0.943

	p.Svg.SetHeight(int(xSize * 3))
	p.Svg.SetWidth(int(xSize * 3))

	i := 0
	for y := 0; y <= 5; y++ {
		for x := 0; x <= 5; x++ {

			val := utils.HexVal(p.Hash, i, 1)
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			var dy float64
			if x%2 == 0 {
				dy = float64(y)*xSize - xSize*0.5
			} else {
				dy = float64(y)*xSize - xSize*0.5 + xSize/4
			}

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity)}

			style := make(map[string]interface{})

			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
			p.Svg.Group(xShape, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", 6*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if y == 0 {
				if x%2 == 0 {
					dy = 6*xSize - xSize/2
				} else {
					dy = 6*xSize - xSize/2 + xSize/4
				}

				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if y == 5 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-11*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if x == 0 && y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", 6*xSize/2-xSize/2, dy-6*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
665935
func (d *Decoder) dequantize3() {
	for gr := 0; gr < 2; gr++ {
		for ch := 0; ch < d.nChannels; ch++ {
			longLow, longHigh := 0, 22
			shortLow, shortHigh := 0, 13
			if d.blockType[gr][ch] == 2 {
				if d.mixedBlockFlag[gr][ch] == 1 {
					longHigh = 8
					shortLow = 3
				} else {
					longLow = 22
				}
			} else {
				shortLow = 13
			}

			for sfb := longLow; sfb < longHigh; sfb++ {
				exp := 326 - 210 + d.globalGain[gr][ch]
				if sfb < 21 {
					k := d.scalefacL[gr][ch][sfb]
					k += d.preflag[gr][ch] * pretab[sfb]
					k <<= uint(d.scalefacScale[gr][ch] + 1)
					exp -= k
				}
				q := exp2[exp]
				low := scfBandsL[d.samplingFreq][sfb]
				high := scfBandsL[d.samplingFreq][sfb+1]
				for n := low; n < high; n++ {
					d.huffmanData[gr][ch][n] *= q
				}
			}

			for sfb := shortLow; sfb < shortHigh; sfb++ {
				low := scfBandsS[d.samplingFreq][sfb]
				length := scfBandsS[d.samplingFreq][sfb+1] - low
				for window := 0; window < 3; window++ {
					exp := 326 - 210 + d.globalGain[gr][ch]
					exp -= 8 * d.subblockGain[gr][ch][window]
					if sfb < 12 {
						k := d.scalefacS[gr][ch][sfb][window]
						k <<= uint(d.scalefacScale[gr][ch] + 1)
						exp -= k
					}
					q := exp2[exp]
					winLow := 3*low + window*length
					winHigh := winLow + length
					for n := winLow; n < winHigh; n++ {
						d.huffmanData[gr][ch][n] *= q
					}
				}
			}
		}
	}
}
571455
func (t *Text) makeBufferData(indices []rune) {
	glyphs := t.Font.Config.Glyphs

	vboIndex := 0
	eboIndex := 0
	lineX := float32(0)
	eboOffset := int32(0)

	t.CharSpacing = make([]float32, 0)
	for i, r := range indices {
		glyphIndex := t.Font.Config.RuneRanges.GetGlyphIndex(r)
		if glyphIndex >= 0 {
			if gltext.IsDebug {
				prefix := gltext.DebugPrefix()
				fmt.Printf("%s png index %3d: %s rune %+v line at %f", prefix, glyphIndex, string(r), glyphs[glyphIndex], lineX)
			}
			advance := float32(glyphs[glyphIndex].Advance)

			// Originally the glyph Width was used, but that results in quads that overlap one another.
			vw := float32(glyphs[glyphIndex].Advance)
			vh := float32(glyphs[glyphIndex].Height)

			// used to determine which character inside of the text was clicked
			t.CharSpacing = append(t.CharSpacing, advance)

			// variable width characters will produce a bounding box that is just
			// a bit too long on the right-hand side unless we trim off the excess
			// when processing the right-most character
			trim := float32(0)
			if i == len(indices)-1 {
				trim = vw - advance
			}
			tP1, tP2 := glyphs[glyphIndex].GetTexturePositions(t.Font)

			// counter-clockwise quad
			// the bounding box value X2 is being expanded as characters are added

			// index (0,0)
			t.vboData[vboIndex] = lineX // position
			vboIndex++
			t.vboData[vboIndex] = 0
			vboIndex++
			t.vboData[vboIndex] = tP1.X // texture uv
			vboIndex++
			t.vboData[vboIndex] = tP2.Y
			vboIndex++

			// index (1,0) - expanding X2
			t.vboData[vboIndex], t.X2.X = lineX+vw, lineX+vw-trim
			vboIndex++
			t.vboData[vboIndex] = 0
			vboIndex++
			t.vboData[vboIndex] = tP2.X
			vboIndex++
			t.vboData[vboIndex] = tP2.Y
			vboIndex++

			// index (1,1) - expanding X2
			t.vboData[vboIndex] = lineX + vw
			vboIndex++
			t.vboData[vboIndex], t.X2.Y = vh, vh
			vboIndex++
			t.vboData[vboIndex] = tP2.X
			vboIndex++
			t.vboData[vboIndex] = tP1.Y
			vboIndex++

			// index (0,1)
			t.vboData[vboIndex] = lineX
			vboIndex++
			t.vboData[vboIndex] = vh
			vboIndex++
			t.vboData[vboIndex] = tP1.X
			vboIndex++
			t.vboData[vboIndex] = tP1.Y
			vboIndex++

			// ebo data
			t.eboData[eboIndex] = 0 + eboOffset
			eboIndex++
			t.eboData[eboIndex] = 1 + eboOffset
			eboIndex++
			t.eboData[eboIndex] = 2 + eboOffset
			eboIndex++

			t.eboData[eboIndex] = 0 + eboOffset
			eboIndex++
			t.eboData[eboIndex] = 2 + eboOffset
			eboIndex++
			t.eboData[eboIndex] = 3 + eboOffset
			eboIndex++
			eboOffset += 4

			// shift to the right
			lineX += advance
			if gltext.IsDebug {
				fmt.Printf("-> %f\n", lineX)
			}
		}
	}
	if gltext.IsDebug {
		gltext.PrintVBO(t.vboData, t.Font.GetTextureHeight(), t.Font.GetTextureWidth())
	}
	return
}