package official_climb import ( "math" "github.com/jftuga/geodist" "github.com/martinlehoux/biking_home/geo" ) // MatchedClimb is an official climb that lies on a route, together with the // route point indexes of its start and end. It lets the climb detector know // which segment of the route is already claimed by an official climb. type MatchedClimb struct { OfficialClimb StartIndex int EndIndex int } // MatchClimb matches an official climb against a route purely by // coordinates: both the start and end coordinates must be within radiusM of a // route point, and the matched start point must precede the matched end point. func MatchClimb(route []geodist.Coord, official OfficialClimb, radiusM float64) (MatchedClimb, bool) { if math.IsNaN(radiusM) || math.IsInf(radiusM, 0) || radiusM <= 0 { return MatchedClimb{}, false } startIndex, startDistance := geo.Nearest(route, official.StartCoord) endIndex, endDistance := geo.Nearest(route, official.EndCoord) if startDistance > radiusM || endDistance > radiusM { return MatchedClimb{}, false } if startIndex >= endIndex { return MatchedClimb{}, false } return MatchedClimb{OfficialClimb: official, StartIndex: startIndex, EndIndex: endIndex}, true }