aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/paulmach/orb/planar/distance.go
blob: a0304a7faf01c2f4b8c2422bd7321fa5f29e9227 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package planar

import (
	"math"

	"github.com/paulmach/orb"
)

// Distance returns the distance between two points in 2d euclidean geometry.
func Distance(p1, p2 orb.Point) float64 {
	d0 := (p1[0] - p2[0])
	d1 := (p1[1] - p2[1])
	return math.Sqrt(d0*d0 + d1*d1)
}

// DistanceSquared returns the square of the distance between two points in 2d euclidean geometry.
func DistanceSquared(p1, p2 orb.Point) float64 {
	d0 := (p1[0] - p2[0])
	d1 := (p1[1] - p2[1])
	return d0*d0 + d1*d1
}