// MaxDistanceToCell returns the maximum distance from the cell (including its
// interior) to the given target cell.
775859
func (c Cell) MaxDistanceToCell(target Cell) s1.ChordAngle {
	// Need to check the antipodal target for intersection with the cell. If it
	// intersects, the distance is the straight ChordAngle.
	// antipodalUV is the transpose of the original UV, interpreted within the opposite face.
	antipodalUV := r2.Rect{target.uv.Y, target.uv.X}
	if int(c.face) == oppositeFace(int(target.face)) && c.uv.Intersects(antipodalUV) {
		return s1.StraightChordAngle
	}

	// Otherwise, the maximum distance always occurs between a vertex of one
	// cell and an edge of the other cell (including the edge endpoints).  This
	// represents a total of 32 possible (vertex, edge) pairs.
	//
	// TODO(roberts): When the maximum distance is at most π/2, the maximum is
	// always attained between a pair of vertices, and this could be made much
	// faster by testing each vertex pair once rather than the current 4 times.
	var va, vb [4]Point
	for i := 0; i < 4; i++ {
		va[i] = c.Vertex(i)
		vb[i] = target.Vertex(i)
	}
	maxDist := s1.NegativeChordAngle
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			maxDist, _ = UpdateMaxDistance(va[i], vb[j], vb[(j+1)&3], maxDist)
			maxDist, _ = UpdateMaxDistance(vb[i], va[j], va[(j+1)&3], maxDist)
		}
	}
	return maxDist
}
580086
func Max(values ...time.Duration) time.Duration {
	var (
		max time.Duration
	)

	for _, v := range values {
		if v > max {
			max = v
		}
	}

	return max
}
562026
func inRange(r headerutil.Range) scope {
	var scope composedScope

	if r.Max != nil {
		scope = append(scope, limit(*r.Max))
	}

	if r.Sort != nil && r.Order != nil {
		o := fmt.Sprintf("%s %s", *r.Sort, *r.Order)
		scope = append(scope, order(o))
	}

	return scope
}
610290
func (r *rangeIterator) seekTo(target *rangeIterator) {
	r.it.seek(target.rangeMin)
	// If the current cell does not overlap target, it is possible that the
	// previous cell is the one we are looking for. This can only happen when
	// the previous cell contains target but has a smaller CellID.
	if r.it.Done() || r.it.CellID().RangeMin() > target.rangeMax {
		if r.it.Prev() && r.it.CellID().RangeMax() < target.cellID() {
			r.it.Next()
		}
	}
	r.refresh()
}
744325
func max(values ...int) int {
	v := 0
	for _, i := range values {
		if i > v {
			v = i
		}
	}
	return v
}
519843
func (p *Point) GeoDistanceFrom(point *Point, haversine ...bool) float64 {
	dLat := deg2rad(point.Lat() - p.Lat())
	dLng := math.Abs(deg2rad(point.Lng() - p.Lng()))

	if yesHaversine(haversine) {
		// yes trig functions
		dLat2Sin := math.Sin(dLat / 2)
		dLng2Sin := math.Sin(dLng / 2)
		a := dLat2Sin*dLat2Sin + math.Cos(deg2rad(p.Lat()))*math.Cos(deg2rad(point.Lat()))*dLng2Sin*dLng2Sin

		return 2.0 * EarthRadius * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
	}

	if dLng > math.Pi {
		dLng = 2*math.Pi - dLng
	}

	// fast way using pythagorean theorem on an equirectangular projection
	x := dLng * math.Cos(deg2rad((p.Lat()+point.Lat())/2.0))
	return math.Sqrt(dLat*dLat+x*x) * EarthRadius
}
451764
func (n *node) RangeScan(min, max string) []Node {
	if n.tx != nil {
		return n.rangeScan(n.tx, min, max)
	}

	var nodes []Node

	n.readTx(func(tx *bolt.Tx) error {
		nodes = n.rangeScan(tx, min, max)
		return nil
	})

	return nodes
}
591626
func SortByDistance(sp KeySpace, center Key, toSort []Key) []Key {
	toSortCopy := make([]Key, len(toSort))
	copy(toSortCopy, toSort)
	bdtc := &byDistanceToCenter{
		Center: center,
		Keys:   toSortCopy, // copy
	}
	sort.Sort(bdtc)
	return bdtc.Keys
}
9734
func (cu *CellUnion) RectBound() Rect {
	bound := EmptyRect()
	for _, c := range *cu {
		bound = bound.Union(CellFromCellID(c).RectBound())
	}
	return bound
}
164231
func Distance(a, b *T) float64 {
	d := Sub(a, b)
	return d.Length()
}
569119
func UInt8Range(min, max uint8) gopter.Gen {
	return UInt64Range(uint64(min), uint64(max)).
		Map(uint64To8).
		WithShrinker(UInt8Shrinker).
		SuchThat(func(v uint8) bool {
			return v >= min && v <= max
		})
}
501578
func (p *Polyline) IntersectsCell(cell Cell) bool {
	if len(*p) == 0 {
		return false
	}

	// We only need to check whether the cell contains vertex 0 for correctness,
	// but these tests are cheap compared to edge crossings so we might as well
	// check all the vertices.
	for _, v := range *p {
		if cell.ContainsPoint(v) {
			return true
		}
	}

	cellVertices := []Point{
		cell.Vertex(0),
		cell.Vertex(1),
		cell.Vertex(2),
		cell.Vertex(3),
	}

	for j := 0; j < 4; j++ {
		crosser := NewChainEdgeCrosser(cellVertices[j], cellVertices[(j+1)&3], (*p)[0])
		for i := 1; i < len(*p); i++ {
			if crosser.ChainCrossingSign((*p)[i]) != DoNotCross {
				// There is a proper crossing, or two vertices were the same.
				return true
			}
		}
	}
	return false
}
59446
func (c *Connect) GetCellsFreeMemory(startCell int, maxCells int) ([]uint64, error) {
	cmem := make([]C.ulonglong, maxCells)
	var err C.virError
	ret := C.virNodeGetCellsFreeMemoryWrapper(c.ptr, (*C.ulonglong)(unsafe.Pointer(&cmem[0])), C.int(startCell), C.int(maxCells), &err)
	if ret == -1 {
		return []uint64{}, makeError(&err)
	}

	mem := make([]uint64, ret)
	for i := 0; i < int(ret); i++ {
		mem[i] = uint64(cmem[i])
	}

	return mem, nil
}
494403
func intMaxRange(root, left, right *IntNode) int {
	end := root.Interval.End
	if left != nil && left.Range.End > end {
		end = left.Range.End
	}
	if right != nil && right.Range.End > end {
		end = right.Range.End
	}
	return end
}
346888
func CellUnionFromDifference(x, y CellUnion) CellUnion {
	// TODO(roberts): This is approximately O(N*log(N)), but could probably
	// use similar techniques as CellUnionFromIntersectionWithCellID to be more efficient.

	var cu CellUnion
	for _, xid := range x {
		cu.cellUnionDifferenceInternal(xid, &y)
	}

	// The output is generated in sorted order, and there should not be any
	// cells that can be merged (provided that both inputs were normalized).
	return cu
}
1159858
func Distance(a, b *T) float32 {
	d := Sub(a, b)
	return d.Length()
}
771962
func LOGetCell(worksheet *ole.IDispatch, nColumn int, nRow int) (cell *ole.IDispatch) {
	return oleutil.MustCallMethod(worksheet, "getCellByPosition", nColumn, nRow).ToIDispatch()
}