// Normalize normalizes the CellUnion.
517234
func (cu *CellUnion) Normalize() {
	sort.Sort(byID(*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 {
			fin := output[len(output)-3:]

			// fast XOR test; a necessary but not sufficient condition
			if fin[0]^fin[1]^fin[2]^ci != 0 {
				break
			}

			// more expensive test; exact.
			// Compute the two bit mask for the encoded child position,
			// then see if they all agree.
			mask := CellID(ci.lsb() << 1)
			mask = ^(mask + mask<<1)
			should := ci & mask
			if (fin[0]&mask != should) || (fin[1]&mask != should) || (fin[2]&mask != should) || ci.isFace() {
				break
			}

			output = output[:len(output)-3]
			ci = ci.immediateParent() // checked !ci.isFace above
		}
		output = append(output, ci)
	}
	*cu = output
}
814983
func (t *Quest_Desc_Meta_Timeouts) Normalize() error {
	if d := google.DurationFromProto(t.Start); d < 0 {
		return fmt.Errorf("desc.meta.timeouts.start < 0: %s", d)
	}
	if d := google.DurationFromProto(t.Run); d < 0 {
		return fmt.Errorf("desc.meta.timeouts.run < 0: %s", d)
	}
	if d := google.DurationFromProto(t.Stop); d < 0 {
		return fmt.Errorf("desc.meta.timeouts.stop < 0: %s", d)
	}
	return nil
}
1000214
func normalizeImage(image string) string {
	if strings.Contains(image, ":") {
		t := strings.Split(image, ":")
		return t[0]
	}
	return image
}
1115788
func (i *Config_Isolate) Normalize() (err error) {
	if err = schemaHostURLValidate(i.Url); err != nil {
		return fmt.Errorf("config.isolate.host: %s", err)
	}
	return
}
93927
func normalize(c context.Context, cfg *Config) error {
	for _, p := range cfg.Projects.GetProject() {
		p.Revision = cfg.revision
	}
	for _, v := range cfg.VMs.GetVms() {
		for _, ch := range v.Amount.GetChange() {
			if err := ch.Length.Normalize(); err != nil {
				return errors.Annotate(err, "failed to normalize %q", v.Prefix).Err()
			}
		}
		if err := v.Lifetime.Normalize(); err != nil {
			return errors.Annotate(err, "failed to normalize %q", v.Prefix).Err()
		}
		v.Revision = cfg.revision
		if err := v.Timeout.Normalize(); err != nil {
			return errors.Annotate(err, "failed to normalize %q", v.Prefix).Err()
		}
	}
	return nil
}
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
}
1255817
func (c *CipdSpec) Normalize() error {
	if err := schemaHostURLValidate(c.Server); err != nil {
		return fmt.Errorf("job.inputs.cipd.server: %s", err)
	}
	if c.Client != nil {
		if err := c.Client.Normalize(); err != nil {
			return fmt.Errorf("job.inputs.cipd.client: %s", err)
		}
	}
	for path, pkgs := range c.ByPath {
		for i, p := range pkgs.Pkg {
			if err := p.Normalize(); err != nil {
				return fmt.Errorf("job.inputs.cipd.by_path[%s].pkg[%d]: %s", path, i, err)
			}
		}
	}
	return nil
}
535382
func (a *ActivateExecutionReq) Normalize() error {
	if err := a.Auth.Normalize(); err != nil {
		return err
	}
	if len(a.ExecutionToken) < MinimumActivationTokenLength {
		return fmt.Errorf("insufficiently long ExecutionToken: %d",
			len(a.ExecutionToken))
	}
	return nil
}
781399
func normalize(v reflect.Value) interface{} {
	k := v.Kind()

	switch {
	case isNumber(k):
		f, err := numberToFloat(v)
		if err == nil {
			return f
		}
	}

	return v.Interface()
}
856695
func (p *Parameters) Normalize() (err error) {
	if err = p.Scheduling.Normalize(); err != nil {
		return
	}
	if err = p.Meta.Normalize(); err != nil {
		return
	}
	if err = p.Job.Normalize(); err != nil {
		return
	}
	return
}
116941
func (p *Point) Normalize() *Point {
	dist := math.Sqrt(p[0]*p[0] + p[1]*p[1])

	if dist == 0 {
		p[0] = 0
		p[1] = 0

		return p
	}

	p[0] /= dist
	p[1] /= dist

	return p
}
120329
func (f *File) Normalize() error {
	for tempName, t := range f.Template {
		if err := t.Normalize(); err != nil {
			return fmt.Errorf("template %q: %s", tempName, err)
		}
	}
	return nil
}
949348
func Normalize(angle float64) float64 {
	for angle > math.Pi {
		angle -= piTimes2
	}
	for angle <= -math.Pi {
		angle += piTimes2
	}
	return angle
}
922693
func (step *StepModel) Normalize() error {
	for _, input := range step.Inputs {
		if err := input.Normalize(); err != nil {
			return err
		}
	}

	for _, output := range step.Outputs {
		if err := output.Normalize(); err != nil {
			return err
		}
	}

	normalizedMeta, err := JSONMarshallable(step.Meta)
	if err != nil {
		return err
	}
	step.Meta = normalizedMeta

	return nil
}
822063
func (r *Range) Normalize() error {
	if r.High <= r.Low {
		return fmt.Errorf("malformed Range")
	}
	return nil
}
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
}
81711
func (s *stateV4) normalize() {
	sort.Stable(sortResourcesV4(s.Resources))
	for _, rs := range s.Resources {
		sort.Stable(sortInstancesV4(rs.Instances))
	}
}