// distanceInternal reports the distance from the given point to the interior of
// the cell if toInterior is true or to the boundary of the cell otherwise.
541260
func (c Cell) distanceInternal(targetXYZ Point, toInterior bool) s1.ChordAngle {
	// All calculations are done in the (u,v,w) coordinates of this cell's face.
	target := faceXYZtoUVW(int(c.face), targetXYZ)

	// Compute dot products with all four upward or rightward-facing edge
	// normals. dirIJ is the dot product for the edge corresponding to axis
	// I, endpoint J. For example, dir01 is the right edge of the Cell
	// (corresponding to the upper endpoint of the u-axis).
	dir00 := target.X - target.Z*c.uv.X.Lo
	dir01 := target.X - target.Z*c.uv.X.Hi
	dir10 := target.Y - target.Z*c.uv.Y.Lo
	dir11 := target.Y - target.Z*c.uv.Y.Hi
	inside := true
	if dir00 < 0 {
		inside = false // Target is to the left of the cell
		if c.vEdgeIsClosest(target, false) {
			return edgeDistance(-dir00, c.uv.X.Lo)
		}
	}
	if dir01 > 0 {
		inside = false // Target is to the right of the cell
		if c.vEdgeIsClosest(target, true) {
			return edgeDistance(dir01, c.uv.X.Hi)
		}
	}
	if dir10 < 0 {
		inside = false // Target is below the cell
		if c.uEdgeIsClosest(target, false) {
			return edgeDistance(-dir10, c.uv.Y.Lo)
		}
	}
	if dir11 > 0 {
		inside = false // Target is above the cell
		if c.uEdgeIsClosest(target, true) {
			return edgeDistance(dir11, c.uv.Y.Hi)
		}
	}
	if inside {
		if toInterior {
			return s1.ChordAngle(0)
		}
		// Although you might think of Cells as rectangles, they are actually
		// arbitrary quadrilaterals after they are projected onto the sphere.
		// Therefore the simplest approach is just to find the minimum distance to
		// any of the four edges.
		return minChordAngle(edgeDistance(-dir00, c.uv.X.Lo),
			edgeDistance(dir01, c.uv.X.Hi),
			edgeDistance(-dir10, c.uv.Y.Lo),
			edgeDistance(dir11, c.uv.Y.Hi))
	}

	// Otherwise, the closest point is one of the four cell vertices. Note that
	// it is *not* trivial to narrow down the candidates based on the edge sign
	// tests above, because (1) the edges don't meet at right angles and (2)
	// there are points on the far side of the sphere that are both above *and*
	// below the cell, etc.
	return minChordAngle(c.vertexChordDist2(target, false, false),
		c.vertexChordDist2(target, true, false),
		c.vertexChordDist2(target, false, true),
		c.vertexChordDist2(target, true, true))
}
834562
func Distance(p1, p2 orb.Point) float64 {
	dLat := deg2rad(p1[1] - p2[1])
	dLon := deg2rad(p1[0] - p2[0])

	dLon = math.Abs(dLon)
	if dLon > math.Pi {
		dLon = 2*math.Pi - dLon
	}

	// fast way using pythagorean theorem on an equirectangular projection
	x := dLon * math.Cos(deg2rad((p1[1]+p2[1])/2.0))
	return math.Sqrt(dLat*dLat+x*x) * orb.EarthRadius
}
1316529
func (c *Client) DistanceTo(other *Coordinate) time.Duration {
	c.mutex.RLock()
	defer c.mutex.RUnlock()

	return c.coord.DistanceTo(other)
}
236872
func excludeInternal(input, rules reflect.Value) {
	// restore original value by Elm()
	if input.Type().Kind() == reflect.Interface {
		input = input.Elem()
	}
	if rules.Type().Kind() == reflect.Interface {
		rules = rules.Elem()
	}
	if rules.MapIndex(reflect.ValueOf("*")).IsValid() {
		for _, key := range input.MapKeys() {
			excludeInternal(input.MapIndex(key), rules.MapIndex(reflect.ValueOf("*")))
		}
	} else {
		for _, key := range input.MapKeys() {
			value := input.MapIndex(key)
			rule := rules.MapIndex(key)

			if rule.IsValid() {
				// restore original value by Elm()
				if value.Type().Kind() == reflect.Interface {
					value = value.Elem()
				}
				if rule.Type().Kind() == reflect.Interface {
					rule = rule.Elem()
				}

				switch rule.Type().Kind() {
				case reflect.Slice:
					for i := 0; i < rule.Len(); i++ {
						input.SetMapIndex(key, remove(value, find(value, rule.Index(i))))
					}
				case reflect.String:
					if rule.Interface() == "*" {
						input.SetMapIndex(key, reflect.Value{})
					}
				case reflect.Map:
					excludeInternal(value, rule)
				}
			}
		}
	}
}
643284
func ErrorInternal(c web.C, rw http.ResponseWriter, err error) {
	// produce stack backtrace, max 64KB
	const size = 64 << 10 // 64KB
	buf := make([]byte, size)
	buf = buf[:runtime.Stack(buf, false)]
	lines := strings.Split(string(buf), "\n")
	c.Env["stack"] = lines[3:]

	if err != nil {
		ErrorString(c, rw, 500, err.Error())
	} else {
		ErrorString(c, rw, 500, "nil err passed into gojiutil.ErrorInternal")
	}
}
605047
func (g *Geometry) Distance(other *Geometry) (float64, error) {
	return g.binaryFloat("Distance", cGEOSDistance, other)
}
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
}
480056
func InitAll() Env {
	traceCloser := InitTracer()
	metricsCloser := InitMetrics()

	l := InitLogger()
	logger.DefaultLogger = l

	r := InitReporter()

	ctx := reporter.WithReporter(context.Background(), r)
	ctx = logger.WithLogger(ctx, l)

	go func() {
		defer reporter.Monitor(ctx)
		metrics.Runtime()
	}()

	return Env{
		Logger:   l,
		Reporter: r,
		Context:  ctx,
		Close: func() {
			traceCloser()
			metricsCloser()
		},
	}
}
220865
func newInternal(exec utilexec.Interface, dbus utildbus.Interface, protocol Protocol, lockfilePath string) Interface {
	vstring, err := getIPTablesVersionString(exec, protocol)
	if err != nil {
		klog.Warningf("Error checking iptables version, assuming version at least %s: %v", MinCheckVersion, err)
		vstring = MinCheckVersion
	}

	if lockfilePath == "" {
		lockfilePath = LockfilePath16x
	}

	runner := &runner{
		exec:            exec,
		dbus:            dbus,
		protocol:        protocol,
		hasCheck:        getIPTablesHasCheckCommand(vstring),
		hasListener:     false,
		waitFlag:        getIPTablesWaitFlag(vstring),
		restoreWaitFlag: getIPTablesRestoreWaitFlag(exec, protocol),
		lockfilePath:    lockfilePath,
	}
	return runner
}
482953
func (c Cell) MaxDistanceToEdge(a, b Point) s1.ChordAngle {
	// If the maximum distance from both endpoints to the cell is less than π/2
	// then the maximum distance from the edge to the cell is the maximum of the
	// two endpoint distances.
	maxDist := maxChordAngle(c.MaxDistance(a), c.MaxDistance(b))
	if maxDist <= s1.RightChordAngle {
		return maxDist
	}

	return s1.StraightChordAngle - c.DistanceToEdge(Point{a.Mul(-1)}, Point{b.Mul(-1)})
}
124151
func (c Cell) BoundaryDistance(target Point) s1.ChordAngle {
	return c.distanceInternal(target, false)
}
386914
func (m *manager) setInternal(id kubecontainer.ContainerID, result Result) bool {
	m.Lock()
	defer m.Unlock()
	prev, exists := m.cache[id]
	if !exists || prev != result {
		m.cache[id] = result
		return true
	}
	return false
}
469665
func (i Interval) InteriorContains(p float64) bool {
	if p == -math.Pi {
		p = math.Pi
	}
	if i.IsInverted() {
		return p > i.Lo || p < i.Hi
	}
	return (p > i.Lo && p < i.Hi) || i.IsFull()
}
963836
func findAllInternal(node *html.Node, matcher Matcher, searchNested bool) []*html.Node {
	matched := []*html.Node{}

	if matcher(node) {
		matched = append(matched, node)

		if !searchNested {
			return matched
		}
	}

	for c := node.FirstChild; c != nil; c = c.NextSibling {
		found := findAllInternal(c, matcher, searchNested)
		if len(found) > 0 {
			matched = append(matched, found...)
		}
	}
	return matched
}
798815
func (i *BatchIndexer) addInternal(doc *Doc) (int, error) {
	b, err := json.Marshal(&indexDoc{Doc: doc})
	if err != nil {
		return i.cnt, err
	}
	i.buf.Write(b)
	i.buf.Write([]byte("\n"))
	b, err = json.Marshal(doc.Source)
	if err != nil {
		return i.cnt, nil
	}
	i.buf.Write(b)
	i.buf.Write([]byte("\n"))
	i.cnt++
	return i.cnt, nil
}
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
}
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)
}