Skip to content

Commit

Permalink
Merge pull request #139 from SignalK/null-magneticvariation
Browse files Browse the repository at this point in the history
Fix: handling of null magneticVariation
  • Loading branch information
tkurki authored Aug 10, 2024
2 parents ffb40e4 + 5c5f05d commit 3ad42f1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
9 changes: 6 additions & 3 deletions calcs/courseOverGroundMagnetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module.exports = function (app, plugin) {
magneticVariation = app.getSelfPath(
'navigation.magneticVariation.value'
)
if (_.isUndefined(magneticVariation)) {
return
}
}
if (_.isUndefined(magneticVariation) || magneticVariation === null) {
return
}
if (
_.isUndefined(courseOverGroundTrue) ||
Expand Down Expand Up @@ -46,6 +46,9 @@ module.exports = function (app, plugin) {
{
input: [null, -0.01],
expected: [{ path: 'navigation.courseOverGroundMagnetic', value: null }]
},
{
input: [0.2, null]
}
]
}
Expand Down
9 changes: 6 additions & 3 deletions calcs/courseOverGroundTrue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module.exports = function (app, plugin) {
magneticVariation = app.getSelfPath(
'navigation.magneticVariation.value'
)
if (_.isUndefined(magneticVariation)) {
return
}
}
if (_.isUndefined(magneticVariation) || magneticVariation === null) {
return
}
if (
_.isUndefined(courseOverGroundMagnetic) ||
Expand All @@ -39,6 +39,9 @@ module.exports = function (app, plugin) {
{
input: [null, 0.01],
expected: [{ path: 'navigation.courseOverGroundTrue', value: null }]
},
{
input: [0.2, null]
}
]
}
Expand Down
9 changes: 6 additions & 3 deletions calcs/headingTrue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports = function (app, plugin) {
magneticVariation = app.getSelfPath(
'navigation.magneticVariation.value'
)
if (_.isUndefined(magneticVariation)) {
return
}
}
if (_.isUndefined(magneticVariation) || magneticVariation === null) {
return
}
if (_.isUndefined(heading) || heading === null) {
return [{ path: 'navigation.headingTrue', value: null }]
Expand All @@ -31,6 +31,9 @@ module.exports = function (app, plugin) {
{
input: [null, 0.01],
expected: [{ path: 'navigation.headingTrue', value: null }]
},
{
input: [0.2, null]
}
]
}
Expand Down
20 changes: 18 additions & 2 deletions calcs/setDrift.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function (app, plugin) {
}

var setTrue = setMagnetic + magneticVariation
if (_.isUndefined(magneticVariation)) {
if (_.isUndefined(magneticVariation) || magneticVariation === null) {
setTrue = null
} else if (setTrue >= 2 * Math.Pi) {
setTrue = setTrue - Math.PI * 2
Expand All @@ -65,6 +65,22 @@ module.exports = function (app, plugin) {
{ path: 'environment.current.setTrue', value: setTrue },
{ path: 'environment.current.setMagnetic', value: setMagnetic }
]
}
},
tests: [
{
input: [0.1, 0.2, 5, 4.5, null],
expected: [
{ path: 'environment.current.drift', value: 0.6890664427243886 },
{
path: 'environment.current.setTrue',
value: null
},
{
path: 'environment.current.setMagnetic',
value: 3.0482899952302343
}
]
}
]
}
}
6 changes: 5 additions & 1 deletion calcs/windDirectionMagnetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (app, plugin) {
'navigation.magneticVariation'
],
calculator: function (directionTrue, magneticVariation) {
if (directionTrue === null) {
if (directionTrue === null || magneticVariation === null) {
return [{ path: 'environment.wind.directionMagnetic', value: null }]
}
var directionMagnetic = directionTrue - magneticVariation
Expand All @@ -25,6 +25,10 @@ module.exports = function (app, plugin) {
{
input: [null, -0.01],
expected: [{ path: 'environment.wind.directionMagnetic', value: null }]
},
{
input: [0.2, null],
expected: [{ path: 'environment.wind.directionMagnetic', value: null }]
}
]
}
Expand Down

0 comments on commit 3ad42f1

Please sign in to comment.