From 1a96cd96f665ee4bd123273756d5a851c6991674 Mon Sep 17 00:00:00 2001 From: chris0348 Date: Thu, 25 Jul 2024 18:39:36 +0200 Subject: [PATCH] fix: In trueWind.js derived values are now set to null in case that the input is null. In trueWind.js derived values are now set to null in case that the input is null. Before a AWS of null resulted in a TWS of 0. --- calcs/trueWind.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/calcs/trueWind.js b/calcs/trueWind.js index 5467aff..2ce06c5 100644 --- a/calcs/trueWind.js +++ b/calcs/trueWind.js @@ -10,23 +10,33 @@ module.exports = function (app) { 'environment.wind.angleApparent' ], calculator: function (headTrue, speed, aws, awa) { - var apparentX = Math.cos(awa) * aws - var apparentY = Math.sin(awa) * aws - var angle = Math.atan2(apparentY, -speed + apparentX) - var speed = Math.sqrt( - Math.pow(apparentY, 2) + Math.pow(-speed + apparentX, 2) - ) + var angle + var speed + var dir - if (aws < 1e-9) { - angle = awa - } + if (headTrue == null || speed == null || aws == null || awa == null) { + angle = null + speed = null + dir = null + } else { + var apparentX = Math.cos(awa) * aws + var apparentY = Math.sin(awa) * aws + angle = Math.atan2(apparentY, -speed + apparentX) + speed = Math.sqrt( + Math.pow(apparentY, 2) + Math.pow(-speed + apparentX, 2) + ) + + if (aws < 1e-9) { + angle = awa + } - var dir = headTrue + angle + dir = headTrue + angle - if (dir > Math.PI * 2) { - dir = dir - Math.PI * 2 - } else if (dir < 0) { - dir = dir + Math.PI * 2 + if (dir > Math.PI * 2) { + dir = dir - Math.PI * 2 + } else if (dir < 0) { + dir = dir + Math.PI * 2 + } } return [