-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel_expression_haversine.go
66 lines (53 loc) · 1.2 KB
/
model_expression_haversine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// © 2019-present nextmv.io inc
package nextroute
import (
"fmt"
"github.com/nextmv-io/nextroute/common"
)
// NewHaversineExpression returns a new HaversineExpression.
func NewHaversineExpression() DistanceExpression {
return &haversineExpression{
index: NewModelExpressionIndex(),
name: "haversine",
}
}
type haversineExpression struct {
name string
index int
}
func (h *haversineExpression) HasNegativeValues() bool {
return false
}
func (h *haversineExpression) HasPositiveValues() bool {
return true
}
func (h *haversineExpression) String() string {
return fmt.Sprintf("haversine[%v]",
h.index,
)
}
func (h *haversineExpression) Distance(
vehicleType ModelVehicleType,
from, to ModelStop,
) common.Distance {
return common.NewDistance(h.Value(vehicleType, from, to), common.Meters)
}
func (h *haversineExpression) Index() int {
return h.index
}
func (h *haversineExpression) Name() string {
return h.name
}
func (h *haversineExpression) SetName(n string) {
h.name = n
}
func (h *haversineExpression) Value(
vehicle ModelVehicleType,
from ModelStop,
to ModelStop,
) float64 {
return haversineDistance(
from.Location(),
to.Location(),
).Value(vehicle.Model().DistanceUnit())
}