Skip to content

Commit

Permalink
removing piBy180 from critical path (livekit#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamakrishnaChilaka authored Jul 11, 2022
1 parent bb73011 commit 677b7c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/routing/selector/regionaware.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,19 @@ func hsin(theta float64) float64 {
return math.Pow(math.Sin(theta/2), 2)
}

var piBy180 = math.Pi / 180

// Haversine Distance Formula
// http://en.wikipedia.org/wiki/Haversine_formula
// from https://gist.github.com/cdipaolo/d3f8db3848278b49db68
func distanceBetween(lat1, lon1, lat2, lon2 float64) float64 {
// convert to radians
// must cast radius as float to multiply later
var la1, lo1, la2, lo2, r float64
la1 = lat1 * math.Pi / 180
lo1 = lon1 * math.Pi / 180
la2 = lat2 * math.Pi / 180
lo2 = lon2 * math.Pi / 180
la1 = lat1 * piBy180
lo1 = lon1 * piBy180
la2 = lat2 * piBy180
lo2 = lon2 * piBy180

r = 6378100 // Earth radius in METERS

Expand Down

0 comments on commit 677b7c1

Please sign in to comment.