-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.go
More file actions
95 lines (79 loc) · 2.39 KB
/
analysis.go
File metadata and controls
95 lines (79 loc) · 2.39 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"math"
)
// units for Distance and Speed functions,
// expressed as the length of one degree of longitude at the equator
type unit float64
const EquatorialRadius = 6378
const km unit = 2 * math.Pi * EquatorialRadius / 360
const meter unit = 1000 * km
const nm unit = 60
func (u unit) distance() string {
switch u {
case km:
return "km"
case meter:
return "m"
case nm:
return "nm"
default:
panic(fmt.Errorf("unknown unit %f", u))
}
}
func (u unit) convertDistance(d float64, from unit) float64 {
return d * float64(u) / float64(from)
}
func (u unit) speed() string {
switch u {
case km:
return "km/h"
case meter:
return "m/s"
case nm:
return "kts" // nm/h
default:
panic(fmt.Errorf("unknown unit %f", u))
}
}
// NOTE: all distance values are in distanceUnits!
// longDistanceUnit can be used to convert the distance values to larger units if desired, e.g. full track length
type AnalysisParameters struct {
distanceUnit unit // what is point distance measured in
longDistanceUnit unit // unit to use for longer distance (e.g. track distance)
speedUnit unit // what is speed measured in (in distance units, time is implied m/s, km/h, nm/h=kts)
lookAround float64 // how far back and ahead to look when analyzing a point (in distanceUnits)
movingSpeed float64 // what's the minimum speed to be considered as moving as opposed to stationary (in speedUnits)
turningChange int // what's the minimum heading change to consider the point to be part of a turn (in degrees)
}
func (params *AnalysisParameters) asLongDistance(dist float64) float64 {
return params.longDistanceUnit.convertDistance(dist, params.distanceUnit)
}
func (params *AnalysisParameters) distance() string {
return params.distanceUnit.distance()
}
func (params *AnalysisParameters) longDistance() string {
return params.longDistanceUnit.distance()
}
func (params *AnalysisParameters) speed() string {
return params.speedUnit.speed()
}
type Activity *AnalysisParameters
var Sailing Activity = &AnalysisParameters{
distanceUnit: meter,
longDistanceUnit: nm,
speedUnit: nm,
lookAround: 50, // m
movingSpeed: 1, // kts
turningChange: 60, // degrees
}
var Activities = map[string]Activity{
"sail": Sailing,
}
var KnownActivities []string
func init() {
for a := range Activities {
KnownActivities = append(KnownActivities, a)
}
}