//returns the square distance between two vectors.
977500
func DistSqr(v1, v2 Vect) Float {
	return (v1.X-v2.X)*(v1.X-v2.X) + (v1.Y-v2.Y)*(v1.Y-v2.Y)
}
748246
func LeastSquares(xs, ys []float64) (m, b float64, err error) {

	lx, ly := len(xs), len(ys)

	// If the arrays are not of equal length, we can't do anything
	if lx != ly {
		err = ErrUnequalArrays
		return
	}

	// If we don't have at least two points, we can't do anything
	if lx < 2 {
		err = ErrInsufficientData
		return
	}

	var (
		x, y, meanx, meany, sumxx, sumxy float64
		i                                int
	)

	// Since we're dealing with sums of squares, we'll need to shift the data
	// to be centered around the origin to prevent potential overflow or
	// numerical instability. We'll do this by subtracting the mean of x from
	// each x value, and the mean of y from each y value. This takes an extra
	// pass in each case, but will be much more accurate, since we won't
	// compound rounding errors produced by summing squares of large floats.
	meanx = Mean(xs)
	meany = Mean(ys)

	for i, x = range xs {
		y = ys[i] - meany
		x = x - meanx
		sumxx += x * x
		sumxy += x * y
	}

	// Least squares gets a lot simpler when you subtract the means, because
	// sum of x-values and sum of y-values are both zero.
	m = sumxy / sumxx

	// Shift our y-intercept back to account for our mean subtraction
	b = meany - (m * meanx)

	return
}
566127
func (c1 Color) DistanceRgb(c2 Color) float64 {
	return math.Sqrt(sq(c1.R-c2.R) + sq(c1.G-c2.G) + sq(c1.B-c2.B))
}
724239
func (p *Point) PointDistance(p2 Point) float32 {
	return math.Sqrt(p.PointDistanceSquared(p2))
}
278664
func (vec *T) LengthSqr() float32 {
	return vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]
}
828889
func (mat *MatMxN) ApproxEqual(m2 *MatMxN) bool {
	if mat == m2 {
		return true
	}
	if mat.m != m2.m || mat.n != m2.n {
		return false
	}

	for i, el := range mat.dat {
		if !FloatEqual(el, m2.dat[i]) {
			return false
		}
	}

	return true
}
1280793
func Cross(a, b Vect) Float {
	return (a.X * b.Y) - (a.Y * b.X)
}
755991
func (v Vector) ApproxEqual(ov Vector) bool {
	const epsilon = 1e-14
	return math.Abs(v.X-ov.X) < epsilon && math.Abs(v.Y-ov.Y) < epsilon && math.Abs(v.Z-ov.Z) < epsilon
}
1081856
func (a *Location) Distance(b *Location) float64 {
	if a.DataCenter != b.DataCenter {
		return 1000
	}
	if a.Rack != b.Rack {
		return 100
	}
	if a.Server != b.Server {
		return 10
	}
	return 1
}
431462
func (c1 Color) DistanceLuv(c2 Color) float64 {
	l1, u1, v1 := c1.Luv()
	l2, u2, v2 := c2.Luv()
	return math.Sqrt(sq(l1-l2) + sq(u1-u2) + sq(v1-v2))
}
695172
func (v1 Vec3) ApproxEqual(v2 Vec3) bool {
	for i := range v1 {
		if !FloatEqual(v1[i], v2[i]) {
			return false
		}
	}
	return true
}
1159858
func Distance(a, b *T) float32 {
	d := Sub(a, b)
	return d.Length()
}
22015
func (p *Point) PointDistanceSquared(p2 Point) float32 {
	return (p.X-p2.X)*(p.X-p2.X) + (p.Y-p2.Y)*(p.Y-p2.Y)
}
420519
func Rectangular(L int) []float64 {
	r := make([]float64, L)

	for i := range r {
		r[i] = 1
	}

	return r
}
43217
func sumSquares(s metrics.Sample) float64 {
	count := float64(s.Count())
	sumSquared := math.Pow(count*s.Mean(), 2)
	sumSquares := math.Pow(count*s.StdDev(), 2) + sumSquared/count
	if math.IsNaN(sumSquares) {
		return 0.0
	}
	return sumSquares
}
605047
func (g *Geometry) Distance(other *Geometry) (float64, error) {
	return g.binaryFloat("Distance", cGEOSDistance, other)
}
1090929
func EuclideanDistance(u []float64, v []float64) float64 {
	var sum float64
	for i := range u {
		sum += (u[i] - v[i]) * (u[i] - v[i])
	}
	return math.Sqrt(sum)
}