// Normalize returns a set of numbers on the interval [0,1] for a given set of inputs.
// An example: 4,3,2,1 => 0.4, 0.3, 0.2, 0.1
// Caveat; the total may be < 1.0; there are going to be issues with irrational numbers etc.
773846
func (m mathUtil) Normalize(values ...float64) []float64 {
	var total float64
	for _, v := range values {
		total += v
	}
	output := make([]float64, len(values))
	for x, v := range values {
		output[x] = m.RoundDown(v/total, 0.0001)
	}
	return output
}
548249
func (vec *T) Normalize() *T {
	sl := vec.LengthSqr()
	if sl == 0 || sl == 1 {
		return vec
	}
	return vec.Scale(1 / math.Sqrt(sl))
}
473144
func (p *CipdPackage) Normalize() error {
	if p.Name == "" {
		return errors.New("missing name")
	}
	if p.Version == "" {
		return errors.New("missing version")
	}
	return nil
}
822063
func (r *Range) Normalize() error {
	if r.High <= r.Low {
		return fmt.Errorf("malformed Range")
	}
	return nil
}
714596
func (w *WalkGraphReq) Normalize() error {
	if w.Auth != nil {
		if err := w.Auth.Normalize(); err != nil {
			return err
		}
	}

	if w.Query == nil {
		return errors.New("must specify a Query")
	}
	if err := w.Query.Normalize(); err != nil {
		return err
	}

	if w.Mode == nil {
		w.Mode = &WalkGraphReq_Mode{}
	}

	if w.Limit != nil {
		if w.Limit.MaxDepth < -1 {
			return errors.New("limit.max_depth must be >= -1")
		}
		if google.DurationFromProto(w.Limit.GetMaxTime()) < 0 {
			return errors.New("limit.max_time must be positive")
		}
	} else {
		w.Limit = &WalkGraphReq_Limit{}
	}
	if w.Limit.MaxDataSize == 0 {
		w.Limit.MaxDataSize = DefaultLimitMaxDataSize
	}
	if w.Limit.MaxDataSize > MaxLimitMaxDataSize {
		w.Limit.MaxDataSize = MaxLimitMaxDataSize
	}

	if w.Include == nil {
		w.Include = &WalkGraphReq_Include{
			Quest:     &WalkGraphReq_Include_Options{},
			Attempt:   &WalkGraphReq_Include_Options{},
			Execution: &WalkGraphReq_Include_Options{},
		}
	} else {
		if w.Include.Quest == nil {
			w.Include.Quest = &WalkGraphReq_Include_Options{}
		} else if w.Include.Quest.Result || w.Include.Quest.Abnormal || w.Include.Quest.Expired {
			return errors.New("include.quest does not support result, abnormal or expired")
		}

		if w.Include.Attempt == nil {
			w.Include.Attempt = &WalkGraphReq_Include_Options{}
		} else {
			if w.Include.Attempt.Result {
				w.Include.Attempt.Data = true
			}
		}

		if w.Include.Execution == nil {
			w.Include.Execution = &WalkGraphReq_Include_Options{}
		}
	}

	if w.Exclude == nil {
		w.Exclude = &WalkGraphReq_Exclude{}
	}
	return w.Exclude.Normalize()
}
694434
func (c *Config) Normalize() (err error) {
	if err = c.Swarming.Normalize(); err != nil {
		return
	}
	if err = c.Isolate.Normalize(); err != nil {
		return
	}
	return
}
1323718
func Normalize(v Vect) Vect {
	f := 1.0 / Length(v)
	return Vect{v.X * f, v.Y * f}
}
468255
func (vs Values) Normalize() []Value {
	var output []Value
	var total float64

	for _, v := range vs {
		total += v.Value
	}

	for _, v := range vs {
		if v.Value > 0 {
			output = append(output, Value{
				Style: v.Style,
				Label: v.Label,
				Value: util.Math.RoundDown(v.Value/total, 0.0001),
			})
		}
	}
	return output
}
387286
func (f *extFloat) Normalize() (shift uint) {
	mant, exp := f.mant, f.exp
	if mant == 0 {
		return 0
	}
	if mant>>(64-32) == 0 {
		mant <<= 32
		exp -= 32
	}
	if mant>>(64-16) == 0 {
		mant <<= 16
		exp -= 16
	}
	if mant>>(64-8) == 0 {
		mant <<= 8
		exp -= 8
	}
	if mant>>(64-4) == 0 {
		mant <<= 4
		exp -= 4
	}
	if mant>>(64-2) == 0 {
		mant <<= 2
		exp -= 2
	}
	if mant>>(64-1) == 0 {
		mant <<= 1
		exp -= 1
	}
	shift = uint(f.exp - exp)
	f.mant, f.exp = mant, exp
	return
}
1045801
func normalizeNumber(v interface{}) (n interface{}, err error) {
	switch t := v.(type) {

	case json.Number:
		if strings.Contains(t.String(), ".") {
			n, err = t.Float64()
		} else {
			n, err = t.Int64()
		}

	case float32:
		n = float64(t)
	case float64:
		n = t

	case int:
		n = int64(t)
	case int8:
		n = int64(t)
	case int16:
		n = int64(t)
	case int32:
		n = int64(t)
	case int64:
		n = t

	case uint8:
		n = int64(t)
	case uint16:
		n = int64(t)
	case uint32:
		n = int64(t)
	case uint64:
		n = t
		err = fmt.Errorf("%s is not a supported type", reflect.TypeOf(v))

	default:
		n = t
	}

	return
}
1092762
func (p *Point) Normalize() (Point, float32) {
	if p.X == 0 && p.Y == 0 {
		return *p, 0
	}

	mag := math.Sqrt(p.X*p.X + p.Y*p.Y)
	unit := Point{p.X / mag, p.Y / mag}

	return unit, mag
}
686504
func (s *Parameters_Scheduling) Normalize() (err error) {
	if s.Priority > 255 {
		return errors.New("scheduling.priority > 256")
	}
	// Priority == 0 means default.
	if s.Priority == 0 {
		s.Priority = DefaultSwarmingPriority
	}
	for k, v := range s.Dimensions {
		if k == "" {
			return errors.New("scheduling.dimensions: empty dimension key")
		}
		if v == "" {
			return fmt.Errorf("scheduling.dimensions: dimension key %q with empty value", k)
		}
	}
	if google.DurationFromProto(s.IoTimeout) < 0 {
		return errors.New("scheduling.io_timeout: negative timeout not allowed")
	}
	return
}
1021805
func (cu *CellUnion) Normalize() {
	sortCellIDs(*cu)

	output := make([]CellID, 0, len(*cu)) // the list of accepted cells
	// Loop invariant: output is a sorted list of cells with no redundancy.
	for _, ci := range *cu {
		// The first two passes here either ignore this new candidate,
		// or remove previously accepted cells that are covered by this candidate.

		// Ignore this cell if it is contained by the previous one.
		// We only need to check the last accepted cell. The ordering of the
		// cells implies containment (but not the converse), and output has no redundancy,
		// so if this candidate is not contained by the last accepted cell
		// then it cannot be contained by any previously accepted cell.
		if len(output) > 0 && output[len(output)-1].Contains(ci) {
			continue
		}

		// Discard any previously accepted cells contained by this one.
		// This could be any contiguous trailing subsequence, but it can't be
		// a discontiguous subsequence because of the containment property of
		// sorted S2 cells mentioned above.
		j := len(output) - 1 // last index to keep
		for j >= 0 {
			if !ci.Contains(output[j]) {
				break
			}
			j--
		}
		output = output[:j+1]

		// See if the last three cells plus this one can be collapsed.
		// We loop because collapsing three accepted cells and adding a higher level cell
		// could cascade into previously accepted cells.
		for len(output) >= 3 && areSiblings(output[len(output)-3], output[len(output)-2], output[len(output)-1], ci) {
			// Replace four children by their parent cell.
			output = output[:len(output)-3]
			ci = ci.immediateParent() // checked !ci.isFace above
		}
		output = append(output, ci)
	}
	*cu = output
}
924507
func (d *Dependency) Normalize() error {
	if d.Shards == 0 {
		d.Shards = 1
	}
	if err := d.GetAttempts().Normalize(); err != nil {
		return err
	}
	return d.Phrase.Normalize()
}
36343
func Normalize(cmd *cobra.Command) *cobra.Command {
	if len(cmd.Long) > 0 {
		cmd.Long = LongDesc(cmd.Long)
	}
	if len(cmd.Example) > 0 {
		cmd.Example = Examples(cmd.Example)
	}
	return cmd
}
505192
func (g *Geometry) Normalize() error {
	_, err := intFromC("Normalize", cGEOSNormalize(g.g), -1)
	return err
}
288377
func Normalize(name string) string {
	fargs := func(c rune) bool {
		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
	}
	// get function
	return strings.Join(strings.FieldsFunc(name, fargs), "-")
}