Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass null through true/mag conversions #121

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It currently calculates:
* True Wind Direction (based on AWA and headingTrue)
* Ground Wind Angle and Speed (based on SOG, AWA and AWS)
* Magnetic Wind Direction (based on AWA and headingMagnetic)
* Magnetic Wind Direction (based on wind.directionTrue and magneticVarition)
* Magnetic Wind Direction (based on wind.directionTrue and magneticVariation)
* Wind Shift (experimental)
* Moon illumination and times (based on time and navigation.position)
* Sunlight Times: sunrise, sunriseEnd, goldenHourEnd, solarNoon, goldenHour, sunsetStart, sunset, dusk, nauticalDusk, night, nadir, nightEnd, nauticalDawn, dawn (based on time and navigation.position)
Expand Down
10 changes: 10 additions & 0 deletions calcs/courseOverGroundMagnetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = function (app, plugin) {
return
}
}
if (
_.isUndefined(courseOverGroundTrue) ||
courseOverGroundTrue === null
) {
return [{ path: 'navigation.courseOverGroundMagnetic', value: null }]
}
var courseOverGroundMagnetic = courseOverGroundTrue - magneticVariation
if (courseOverGroundMagnetic < 0) {
courseOverGroundMagnetic = Math.PI * 2 + courseOverGroundMagnetic
Expand All @@ -36,6 +42,10 @@ module.exports = function (app, plugin) {
{
input: [1.0, 0.1],
expected: [{ path: 'navigation.courseOverGroundMagnetic', value: 0.9 }]
},
{
input: [null, -0.01],
expected: [{ path: 'navigation.courseOverGroundMagnetic', value: null }]
}
]
}
Expand Down
14 changes: 13 additions & 1 deletion calcs/courseOverGroundTrue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = function (app, plugin) {
return
}
}
if (
_.isUndefined(courseOverGroundMagnetic) ||
courseOverGroundMagnetic === null
) {
return [{ path: 'navigation.courseOverGroundTrue', value: null }]
}
var courseOverGroundTrue = courseOverGroundMagnetic + magneticVariation
if (courseOverGroundTrue < 0) {
courseOverGroundTrue = Math.PI * 2 + courseOverGroundTrue
Expand All @@ -28,6 +34,12 @@ module.exports = function (app, plugin) {
return [
{ path: 'navigation.courseOverGroundTrue', value: courseOverGroundTrue }
]
}
},
tests: [
{
input: [null, 0.01],
expected: [{ path: 'navigation.courseOverGroundTrue', value: null }]
}
]
}
}
11 changes: 10 additions & 1 deletion calcs/headingTrue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ module.exports = function (app, plugin) {
return
}
}
if (_.isUndefined(heading) || heading === null) {
return [{ path: 'navigation.headingTrue', value: null }]
}
var headingTrue = heading + magneticVariation
if (headingTrue < 0) {
headingTrue = Math.PI * 2 + headingTrue
} else if (headingTrue > Math.PI * 2) {
headingTrue = headingTrue - Math.PI * 2
}
return [{ path: 'navigation.headingTrue', value: headingTrue }]
}
},
tests: [
{
input: [null, 0.01],
expected: [{ path: 'navigation.headingTrue', value: null }]
}
]
}
}
11 changes: 10 additions & 1 deletion calcs/windDirectionMagnetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = function (app, plugin) {
'navigation.magneticVariation'
],
calculator: function (directionTrue, magneticVariation) {
if (directionTrue === null) {
return [{ path: 'environment.wind.directionMagnetic', value: null }]
}
var directionMagnetic = directionTrue - magneticVariation
if (directionMagnetic < 0) {
directionMagnetic = Math.PI * 2 + directionMagnetic
Expand All @@ -17,6 +20,12 @@ module.exports = function (app, plugin) {
return [
{ path: 'environment.wind.directionMagnetic', value: directionMagnetic }
]
}
},
tests: [
{
input: [null, -0.01],
expected: [{ path: 'environment.wind.directionMagnetic', value: null }]
}
]
}
}
Loading