// DistanceFrom returns the minimum euclidean distance from the point set.
342512
func (ps PointSet) DistanceFrom(point *Point) (float64, int) {
	dist := math.Inf(1)
	index := 0

	for i := range ps {
		if d := ps[i].SquaredDistanceFrom(point); d < dist {
			dist = d
			index = i
		}
	}

	return math.Sqrt(dist), index
}
410776
func precomputeDistances(p PointSet) (float64, []float64) {
	total := 0.0
	dists := make([]float64, len(p)-1)
	for i := 0; i < len(p)-1; i++ {
		dists[i] = p[i].DistanceFrom(&p[i+1])
		total += dists[i]
	}

	return total, dists
}
1137154
func (p Point) DistanceTo(other Point) float64 {
	dx := math.Pow(float64(p.X-other.X), 2)
	dy := math.Pow(float64(p.Y-other.Y), 2)
	return math.Pow(dx+dy, 0.5)
}
897584
func (e *Euclidean) Distance(vectorX *mat.Dense, vectorY *mat.Dense) float64 {
	subVector := mat.NewDense(1, 1, nil)
	subVector.Reset()
	subVector.Sub(vectorX, vectorY)
	result := e.InnerProduct(subVector, subVector)

	return math.Sqrt(result)
}
917477
func (cd CentroidDistance) ClusterDistance(c1, c2 *Cluster) float64 {
	return c1.Centroid.DistanceFrom(c2.Centroid)
}
1157807
func (p *Polyline) Length() s1.Angle {
	var length s1.Angle

	for i := 1; i < len(*p); i++ {
		length += (*p)[i-1].Distance((*p)[i])
	}
	return length
}
969429
func DistancePointToLine(point, lineStart, lineEnd geom.Coord) float64 {
	// if start = end, then just compute distance to one of the endpoints
	if Equals(lineStart, lineEnd) {
		return Distance(point, lineStart)
	}

	// otherwise use comp.graphics.algorithms Frequently Asked Questions method
	/*
	 * (1) r = AC dot AB
	 *         ---------
	 *         ||AB||^2
	 *
	 * r has the following meaning:
	 *   r=0 P = A
	 *   r=1 P = B
	 *   r<0 P is on the backward extension of AB
	 *   r>1 P is on the forward extension of AB
	 *   0<r<1 P is interior to AB
	 */

	len2 := (lineEnd[0]-lineStart[0])*(lineEnd[0]-lineStart[0]) + (lineEnd[1]-lineStart[1])*(lineEnd[1]-lineStart[1]) + (lineEnd[2]-lineStart[2])*(lineEnd[2]-lineStart[2])
	if math.IsNaN(len2) {
		panic("Ordinates must not be NaN")
	}
	r := ((point[0]-lineStart[0])*(lineEnd[0]-lineStart[0]) + (point[1]-lineStart[1])*(lineEnd[1]-lineStart[1]) + (point[2]-lineStart[2])*(lineEnd[2]-lineStart[2])) / len2

	if r <= 0.0 {
		return Distance(point, lineStart)
	}
	if r >= 1.0 {
		return Distance(point, lineEnd)
	}

	// compute closest point q on line segment
	qx := lineStart[0] + r*(lineEnd[0]-lineStart[0])
	qy := lineStart[1] + r*(lineEnd[1]-lineStart[1])
	qz := lineStart[2] + r*(lineEnd[2]-lineStart[2])
	// result is distance from p to q
	dx := point[0] - qx
	dy := point[1] - qy
	dz := point[2] - qz
	return math.Sqrt(dx*dx + dy*dy + dz*dz)
}
39242
func DistanceFraction(x, a, b Point) float64 {
	d0 := x.Angle(a.Vector)
	d1 := x.Angle(b.Vector)
	return float64(d0 / (d0 + d1))
}
632451
func (p Point) Distance(other Point) float64 {
	var (
		hn = p.Latitude / 180 * math.Pi
		he = p.Longitude / 180 * math.Pi
		n  = other.Latitude / 180 * math.Pi
		e  = other.Longitude / 180 * math.Pi
		co = math.Cos(he-e)*math.Cos(hn)*math.Cos(n) + math.Sin(hn)*math.Sin(n)
		ca = math.Atan(math.Abs(math.Sqrt(1-co*co) / co))
	)

	if co < 0.0 {
		ca = math.Pi - ca
	}

	return r * ca
}
488043
func (l *Line) DistanceFrom(point *Point) float64 {
	// yes duplicate code, but saw a 15% performance increase by removing the function call
	// return math.Sqrt(l.SquaredDistanceFrom(point))
	x := l.a[0]
	y := l.a[1]
	dx := l.b[0] - x
	dy := l.b[1] - y

	if dx != 0 || dy != 0 {
		t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy)

		if t > 1 {
			x = l.b[0]
			y = l.b[1]
		} else if t > 0 {
			x += dx * t
			y += dy * t
		}
	}

	dx = point[0] - x
	dy = point[1] - y

	return math.Sqrt(dx*dx + dy*dy)
}
1112128
func (s *CreateExportTaskInput) SetFrom(v int64) *CreateExportTaskInput {
	s.From = &v
	return s
}
106950
func (s GeoDistanceSort) GeoDistance(geoDistance string) GeoDistanceSort {
	s.geoDistance = &geoDistance
	return s
}
93426
func (s *GeoDistanceSort) DistanceType(distanceType string) *GeoDistanceSort {
	s.distanceType = &distanceType
	return s
}
10214
func (p Point) Distance(b Point) s1.Angle {
	return p.Vector.Angle(b.Vector)
}
1357332
func Distance(p1, p2 orb.Point) float64 {
	d0 := (p1[0] - p2[0])
	d1 := (p1[1] - p2[1])
	return math.Sqrt(d0*d0 + d1*d1)
}
1003445
func (s *PatchOperation) SetFrom(v string) *PatchOperation {
	s.From = &v
	return s
}
521033
func (address *Address) Distance(address2 *Address) AddressDistance {
	return (address.value).Distance(address2.value)
}