// DistanceFrom computes an O(n) distance from the path. Loops over every
// subline to find the minimum distance.
1597
func (p *Path) DistanceFrom(point *Point) float64 {
	return math.Sqrt(p.SquaredDistanceFrom(point))
}
1097957
func Path(from, to Pather) (path []Pather, distance float64, found bool) {
	nm := nodeMap{}
	nq := &priorityQueue{}
	heap.Init(nq)
	fromNode := nm.get(from)
	fromNode.open = true
	heap.Push(nq, fromNode)
	for {
		if nq.Len() == 0 {
			// There's no path, return found false.
			return
		}
		current := heap.Pop(nq).(*node)
		current.open = false
		current.closed = true

		if current == nm.get(to) {
			// Found a path to the goal.
			p := []Pather{}
			curr := current
			for curr != nil {
				p = append(p, curr.pather)
				curr = curr.parent
			}
			return p, current.cost, true
		}

		for _, neighbor := range current.pather.PathNeighbors() {
			cost := current.cost + current.pather.PathNeighborCost(neighbor)
			neighborNode := nm.get(neighbor)
			if cost < neighborNode.cost {
				if neighborNode.open {
					heap.Remove(nq, neighborNode.index)
				}
				neighborNode.open = false
				neighborNode.closed = false
			}
			if !neighborNode.open && !neighborNode.closed {
				neighborNode.cost = cost
				neighborNode.open = true
				neighborNode.rank = cost + neighbor.PathEstimatedCost(to)
				neighborNode.parent = current
				heap.Push(nq, neighborNode)
			}
		}
	}
}
1250706
func ImportFrom(path string) ([]Config, error) {
	var cfgs []Config
	fmt.Println("walking:", path)
	walk := func(filename string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if info.IsDir() {
			return nil
		}
		id := filepath.Base(filepath.Dir(filename))
		base := filepath.Base(filename)
		if !strings.HasSuffix(base, ".json") {
			return nil
		}
		var tmp []Config
		// eat all these errors since we're searching for matching json
		file, _ := os.Open(filename)
		blob, _ := ioutil.ReadAll(file)
		_ = file.Close()
		_ = json.Unmarshal(blob, &tmp)
		for _, c := range tmp {
			if c.LoginURL == "" || c.Username == "" {
				continue
			}
			c.ID = fmt.Sprintf("%s:%s", id, c.Username)
			fmt.Println("importing...", c.ID)
			cfgs = append(cfgs, c)
		}
		return nil
	}
	err := filepath.Walk(path, walk)
	fmt.Printf("loaded %d configs\n", len(cfgs))
	return cfgs, err
}
88895
func DistanceFromSegmentSquared(a, b, point orb.Point) float64 {
	x := a[0]
	y := a[1]
	dx := b[0] - x
	dy := 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 = b[0]
			y = b[1]
		} else if t > 0 {
			x += dx * t
			y += dy * t
		}
	}

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

	return dx*dx + dy*dy
}
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
}
960582
func (b *Bytes) ReadFrom(r io.Reader) (n int64, err error) {
	return b.ReadNFrom(0, r)
}
755346
func (nm *nmVertex) euclideanDistance(other *nmVertex) float64 {
	sum := float64(0)
	// first we want to sum all the distances between the points
	for i, otherPoint := range other.vars {
		// distance between points is defined by (qi-ri)^2
		sum += math.Pow(otherPoint-nm.vars[i], 2)
	}

	return math.Sqrt(sum)
}
127298
func (i *Int32) ReadFrom(r Reader, l int) error {
	if l != UNKNOWN_LEN && l != 4 {
		return errorsp.WithStacksAndMessage(ErrBadFormat, "l = %d", l)
	}

	var arr [4]byte
	if _, err := io.ReadFull(r, arr[:]); err != nil {
		return errorsp.WithStacks(err)
	}
	*i = Int32(arr[0]) | Int32(arr[1])<<8 | Int32(arr[2])<<16 |
		Int32(arr[3])<<24
	return nil
}
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)
}
764734
func (r *Rename) GetFrom() string {
	if r == nil || r.From == nil {
		return ""
	}
	return *r.From
}
108328
func Distance2D(c1, c2 geom.Coord) float64 {
	dx := c1[0] - c2[0]
	dy := c1[1] - c2[1]

	return math.Sqrt(dx*dx + dy*dy)
}
380914
func (e *Error) ReadFrom(r io.Reader) (n int64, err error) {
	n, err = encoding.ReadFrom(r, &e.Type, &e.Code)
	if err != nil {
		return
	}

	e.Data, err = ioutil.ReadAll(r)
	if err != nil {
		return
	}

	return n + int64(len(e.Data)), nil
}
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
}
419998
func (f *FilterOp) GeoDistance(distance string, fields ...GeoField) *FilterOp {
	f.GeoDistMap = make(map[string]interface{})
	f.GeoDistMap["distance"] = distance
	for _, val := range fields {
		f.GeoDistMap[val.Field] = val.GeoLocation
	}

	return f
}
1003987
func (v ByteView) SliceFrom(from int) ByteView {
	if v.b != nil {
		return ByteView{b: v.b[from:]}
	}
	return ByteView{s: v.s[from:]}
}
497645
func (Null) ReadFrom(r Reader, l int) error {
	if l != UNKNOWN_LEN && l != 0 {
		return errorsp.WithStacksAndMessage(ErrBadFormat, "l = %d", l)
	}
	return nil
}
570428
func Distance(str1, str2 string, p *Params) int {
	if p == nil {
		p = defaultParams
	}
	dist, _, _ := Calculate([]rune(str1), []rune(str2), p.maxCost, p.insCost, p.subCost, p.delCost)
	return dist
}