From 9b0fb726706d5bea77be3a8e78e62bcf09845085 Mon Sep 17 00:00:00 2001 From: Alexander Harding Date: Fri, 3 Jan 2025 22:45:25 -0600 Subject: [PATCH] lceanup --- src/features/rap/Row.tsx | 29 ++++------------------------- src/helpers/vector.ts | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 src/helpers/vector.ts diff --git a/src/features/rap/Row.tsx b/src/features/rap/Row.tsx index b52af8a..bf08c33 100644 --- a/src/features/rap/Row.tsx +++ b/src/features/rap/Row.tsx @@ -5,6 +5,9 @@ import Temperature from "./cells/Temperature"; import WindDirection from "./cells/WindDirection"; import WindSpeed from "./cells/WindSpeed"; import { css } from "@emotion/react"; +import { vectorDifferenceMagnitude } from "../../helpers/vector"; + +const DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH = 10; const TableRow = styled.tr<{ opaque: boolean }>` ${({ opaque }) => @@ -40,7 +43,7 @@ export default function Row({ datum.windDirectionInDeg, displayedRapData[index - 1]?.windSpeedInKph, displayedRapData[index - 1]?.windDirectionInDeg, - ) > 10; + ) > DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH; return ( @@ -84,27 +87,3 @@ export default function Row({ ); } - -function vectorDifferenceMagnitude( - speed1: number, - direction1: number, - speed2: number, - direction2: number, -): number { - // Convert directions from degrees to radians - const radian1 = (Math.PI / 180) * direction1; - const radian2 = (Math.PI / 180) * direction2; - - // Convert polar coordinates to Cartesian coordinates - const x1 = speed1 * Math.cos(radian1); - const y1 = speed1 * Math.sin(radian1); - const x2 = speed2 * Math.cos(radian2); - const y2 = speed2 * Math.sin(radian2); - - // Calculate the difference in Cartesian coordinates - const dx = x2 - x1; - const dy = y2 - y1; - - // Calculate the magnitude of the difference vector - return Math.sqrt(dx * dx + dy * dy); -} diff --git a/src/helpers/vector.ts b/src/helpers/vector.ts new file mode 100644 index 0000000..11feac3 --- /dev/null +++ b/src/helpers/vector.ts @@ -0,0 +1,23 @@ +export function vectorDifferenceMagnitude( + speed1: number, + direction1: number, + speed2: number, + direction2: number, +): number { + // Convert directions from degrees to radians + const radian1 = (Math.PI / 180) * direction1; + const radian2 = (Math.PI / 180) * direction2; + + // Convert polar coordinates to Cartesian coordinates + const x1 = speed1 * Math.cos(radian1); + const y1 = speed1 * Math.sin(radian1); + const x2 = speed2 * Math.cos(radian2); + const y2 = speed2 * Math.sin(radian2); + + // Calculate the difference in Cartesian coordinates + const dx = x2 - x1; + const dy = y2 - y1; + + // Calculate the magnitude of the difference vector + return Math.sqrt(dx * dx + dy * dy); +}