// ProjectNormalized returns distance of point projected on this geometry from
// origin, divided by its length.
// This must be a lineal geometry.
427902
func (g *Geometry) ProjectNormalized(p *Geometry) float64 {
	// XXX: error if wrong geometry types
	return float64(cGEOSProjectNormalized(g.g, p.g))
}
140332
func (l *Line) PointDistance(point Point) float32 {
	return math.Sqrt(l.PointDistanceSquared(point))
}
1114307
func (p *PlateCarreeProjection) Project(pt Point) r2.Point {
	return p.FromLatLng(LatLngFromPoint(pt))
}
798591
func (n *normalizedEndpoints) normalize(name string) string {
	n.mux.RLock()
	norm, ok := n.names[name]
	l := len(n.names)
	n.mux.RUnlock()
	if ok {
		return norm
	}
	if l >= n.maxSize {
		return ""
	}
	return n.normalizeWithLock(name)
}
214799
func (t *TemplateInstantiation) Normalize() error {
	if t.Project == "" {
		return errors.New("empty project")
	}
	return t.Specifier.Normalize()
}
1271835
func (app *AppModel) Normalize() error {
	for _, env := range app.Environments {
		if err := env.Normalize(); err != nil {
			return err
		}
	}
	return nil
}
340424
func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) {

	err = validateData(dataPointX, dataPointY)
	if err != nil {
		return math.NaN(), err
	}
	distance = 0
	for i := 0; i < len(dataPointX); i++ {
		distance = distance + ((dataPointX[i] - dataPointY[i]) * (dataPointX[i] - dataPointY[i]))
	}
	return math.Sqrt(distance), 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
}
1130119
func (n *SimpleNameNormalizer) Normalize(name string) string {
	var retMe []byte
	nameBytes := []byte(name)
	for i, b := range nameBytes {
		if n.safeByte(b) {
			if retMe != nil {
				retMe[i] = b
			}
		} else {
			if retMe == nil {
				retMe = make([]byte, len(nameBytes))
				copy(retMe[0:i], nameBytes[0:i])
			}
			retMe[i] = n.Replacement
		}
	}
	if retMe == nil {
		return name
	}
	return string(retMe)
}
935172
func NewMercatorProjection(maxLng float64) Projection {
	return &MercatorProjection{
		xWrap:       2 * maxLng,
		toRadians:   math.Pi / maxLng,
		fromRadians: maxLng / math.Pi,
	}
}
1204891
func (g *Geometry) Project(p *Geometry) float64 {
	// XXX: error if wrong geometry types
	return float64(cGEOSProject(g.g, p.g))
}
954468
func (d *Context) RequireNormalizeIndex(index int) int {
	return int(C.duk_require_normalize_index(d.duk_context, C.duk_idx_t(index)))
}
1271326
func (v *Value) Normalize() error {
	norm, needsNormalization := v.Value.(interface {
		Normalize() error
	})
	if !needsNormalization {
		return nil
	}
	return norm.Normalize()
}
949348
func Normalize(angle float64) float64 {
	for angle > math.Pi {
		angle -= piTimes2
	}
	for angle <= -math.Pi {
		angle += piTimes2
	}
	return angle
}
614516
func (v Vector) Normalize() Vector {
	if v == (Vector{0, 0, 0}) {
		return v
	}
	return v.Mul(1 / v.Norm())
}
548249
func (vec *T) Normalize() *T {
	sl := vec.LengthSqr()
	if sl == 0 || sl == 1 {
		return vec
	}
	return vec.Scale(1 / math.Sqrt(sl))
}
21389
func (p *Polyline) Project(point Point) (Point, int) {
	if len(*p) == 1 {
		// If there is only one vertex, it is always closest to any given point.
		return (*p)[0], 1
	}

	// Initial value larger than any possible distance on the unit sphere.
	minDist := 10 * s1.Radian
	minIndex := -1

	// Find the line segment in the polyline that is closest to the point given.
	for i := 1; i < len(*p); i++ {
		if dist := DistanceFromSegment(point, (*p)[i-1], (*p)[i]); dist < minDist {
			minDist = dist
			minIndex = i
		}
	}

	// Compute the point on the segment found that is closest to the point given.
	closest := Project(point, (*p)[minIndex-1], (*p)[minIndex])
	if closest == (*p)[minIndex] {
		minIndex++
	}

	return closest, minIndex
}