// findMidpoint will find the midpoint of the provided vertices
// and return a new vertex.
322679
func findMidpoint(vertices ...*nmVertex) *nmVertex {
	num := len(vertices) // this is what we divide by
	vars := make([]float64, 0, num)

	for i := 0; i < num; i++ {
		sum := float64(0)
		for _, v := range vertices {
			sum += v.vars[i]
		}
		vars = append(vars, sum/float64(num))
	}

	return &nmVertex{
		vars: vars,
	}
}
377838
func (eit *EgressIPTracker) findEgressIPAllocation(ip net.IP, allocation map[string][]string) (string, bool) {
	bestNode := ""
	otherNodes := false

	for _, node := range eit.nodes {
		if node.offline {
			continue
		}
		egressIPs := allocation[node.nodeName]
		for _, parsed := range node.parsedCIDRs {
			if parsed.Contains(ip) {
				if bestNode != "" {
					otherNodes = true
					if len(allocation[bestNode]) < len(egressIPs) {
						break
					}
				}
				bestNode = node.nodeName
				break
			}
		}
	}

	return bestNode, otherNodes
}
1104277
func (region *Region) ContainsPoint(x, y int) bool {
	ret := C.cairo_region_contains_point(region.Ptr, C.int(x), C.int(y)) != 0
	if err := region.status(); err != nil {
		panic(err)
	}
	return ret
}
604445
func NewBoundFromPoints(corner, oppositeCorner *Point) *Bound {
	b := &Bound{
		sw: corner.Clone(),
		ne: corner.Clone(),
	}

	b.Extend(oppositeCorner)
	return b
}
883055
func (s *DefaultService) LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
	s.mu.Lock()
	defer s.mu.Unlock()

	return s.lookupEndpoints(hostname)
}
1224968
func (endpoint *ApplicationEndpoint) Find(endpoints []ApplicationEndpoint) *ApplicationEndpoint {
	// Yes, this is brute-force linear search, but in practice the lists should be small, few 10s at most
	endpointID := endpoint.GetID()
	for _, entry := range endpoints {
		if entry.GetID() == endpointID {
			return &entry
		}
	}
	return nil
}
135882
func (pattern *MeshPattern) SetControlPoint(pointNum int, x, y float64) {
	C.cairo_mesh_pattern_set_control_point(pattern.Ptr, C.uint(pointNum), C.double(x), C.double(y))
	if err := pattern.status(); err != nil {
		panic(err)
	}
}
105548
func (m Map) Find(pos, end int) (Location, bool) {
	key := Location{
		Pos: pos,
		End: end,
	}
	if loc, ok := m[key]; ok {
		return loc, true
	}
	return key, false
}
1209395
func DistanceFromPointToLineString(layout geom.Layout, p geom.Coord, line []float64) float64 {
	if len(line) < 2 {
		panic(fmt.Sprintf("Line array must contain at least one vertex: %v", line))
	}
	// this handles the case of length = 1
	firstPoint := line[0:2]
	minDistance := internal.Distance2D(p, firstPoint)
	stride := layout.Stride()
	for i := 0; i < len(line)-stride; i += stride {
		point1 := geom.Coord(line[i : i+2])
		point2 := geom.Coord(line[i+stride : i+stride+2])
		dist := DistanceFromPointToLine(p, point1, point2)
		if dist < minDistance {
			minDistance = dist
		}
	}
	return minDistance
}
789978
func (c Cell) vertexChordDist2(p Point, xHi, yHi bool) s1.ChordAngle {
	x := c.uv.X.Lo
	y := c.uv.Y.Lo
	if xHi {
		x = c.uv.X.Hi
	}
	if yHi {
		y = c.uv.Y.Hi
	}

	return ChordAngleBetweenPoints(p, PointFromCoords(x, y, 1))
}
176709
func (q *Quadtree) FindMatching(p *geo.Point, f Filter) geo.Pointer {
	if q.root == nil {
		return nil
	}

	v := &findVisitor{
		point:          p,
		filter:         f,
		closestBound:   q.bound.Clone(),
		maxDistSquared: math.MaxFloat64,
	}

	newVisit(v).Visit(q.root,
		q.bound.Left(), q.bound.Right(),
		q.bound.Bottom(), q.bound.Top(),
	)

	return v.closest
}
465182
func (q *ConvexHullQuery) AddPoint(p Point) {
	q.bound = q.bound.AddPoint(LatLngFromPoint(p))
	q.points = append(q.points, p)
}
403227
func (r *Region) GetEndpoint() string {
	return fmt.Sprintf("%s://%s", r.Protocl, r.CurrentUseEndpoint)
}
138349
func (l *Location) Find() (string, []error) {
	k := kumoru.New()

	k.Get(l.buildFindPath(k.EndPoint.Location))
	k.SignRequest(true)

	resp, body, errs := k.End()

	if resp.StatusCode != 200 {
		errs = append(errs, fmt.Errorf("%s", resp.Status))
	}

	return string(body), errs
}
134389
func LoopFromPoints(pts []Point) *Loop {
	l := &Loop{
		vertices: pts,
	}

	l.initOriginAndBound()
	return l
}
47563
func findImageEndpoint(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (string, error) {
	eo.ApplyDefaults("image")
	url, err := client.EndpointLocator(eo)
	if err != nil {
		return "", fmt.Errorf("error on locating image endpoint")
	}
	return url, nil
}
1055582
func (r Rect) AddPoint(p Point) Rect {
	return Rect{r.X.AddPoint(p.X), r.Y.AddPoint(p.Y)}
}