Skip to content

Commit

Permalink
fix: fixed wind issue
Browse files Browse the repository at this point in the history
  • Loading branch information
benjasper committed Oct 27, 2023
1 parent 42d6a85 commit 4563284
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
35 changes: 17 additions & 18 deletions src/components/special/RunwayAndWindRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ const RunwayPopup = (props: {

// Calculate crosswind components
const crosswindComponent = () =>
props.runwayDirection.windAngle
props.runwayDirection.windAngle !== undefined
? Math.sin((props.runwayDirection.windAngle * Math.PI) / 180) * props.windSpeed
: undefined

// Left or right crosswind by comparing wind direction and runway heading
const crosswindDirection = () => {
if (!props.windDirection) {
if (props.windDirection === undefined) {
return undefined
}

Expand All @@ -83,7 +83,7 @@ const RunwayPopup = (props: {
}

const headwindComponent = () =>
props.runwayDirection.windAngle
props.runwayDirection.windAngle !== undefined
? Math.cos((props.runwayDirection.windAngle * Math.PI) / 180) * props.windSpeed
: undefined
const tailwindComponent = () => (headwindComponent() ? -headwindComponent()! : undefined)
Expand Down Expand Up @@ -115,7 +115,7 @@ const RunwayPopup = (props: {
</span>
</div>

<Show when={props.windSpeed > 0 && props.windDirection && props.windDirection > 0}>
<Show when={props.windSpeed > 0 && props.windDirection != undefined}>
<div class="flex gap-1">
<div
class="my-auto h-3 w-3 flex-shrink-0 rounded-full border-[3px]"
Expand All @@ -129,7 +129,7 @@ const RunwayPopup = (props: {
}}
aria-label={`Wind direction is ${favourableToText(props.runwayDirection.favourableLevel)}`}
/>
<Show when={props.runwayDirection.windAngle}>
<Show when={props.runwayDirection.windAngle !== undefined}>
<span class="text-sm">
Wind angle: {favourableToText(props.runwayDirection.favourableLevel)} (
{Math.round(props.runwayDirection.windAngle!)}°)
Expand All @@ -140,10 +140,9 @@ const RunwayPopup = (props: {

<Show
when={
props.windDirection &&
headwindComponent() &&
Math.round(selectedSpeedUnit().conversionFunction(headwindComponent()!)) > 0 &&
props.windDirection > 0
props.windDirection !== undefined &&
headwindComponent() != undefined &&
Math.round(selectedSpeedUnit().conversionFunction(headwindComponent()!)) > 0
}>
<div class="flex gap-1">
<BsArrowUp
Expand All @@ -160,10 +159,9 @@ const RunwayPopup = (props: {
</Show>
<Show
when={
props.windDirection &&
crosswindComponent() &&
Math.round(selectedSpeedUnit().conversionFunction(crosswindComponent()!)) > 0 &&
props.windDirection > 0
props.windDirection != undefined &&
crosswindComponent() != undefined &&
Math.round(selectedSpeedUnit().conversionFunction(crosswindComponent()!)) > 0
}>
<div class="flex gap-1">
<BsArrowUp
Expand All @@ -181,10 +179,9 @@ const RunwayPopup = (props: {
</Show>
<Show
when={
tailwindComponent() &&
props.windDirection &&
Math.round(selectedSpeedUnit().conversionFunction(tailwindComponent()!)) > 0 &&
props.windDirection > 0
tailwindComponent() != undefined &&
props.windDirection != undefined &&
Math.round(selectedSpeedUnit().conversionFunction(tailwindComponent()!)) > 0
}>
<div class="flex gap-1">
<BsArrowUp
Expand Down Expand Up @@ -277,13 +274,15 @@ const RunwayAndWindRenderer = (props: {
// Calculate the best runway heading
if (props.windSpeed > 1 && props.windDirection && props.windDirection != 0) {
const bestRunways = preparingRunways.filter(runway => {
if (!runway.direction1.windAngle || !runway.direction2.windAngle) {
if (runway.direction1.windAngle === undefined || runway.direction2.windAngle === undefined) {
return
}

return runway.direction1.windAngle < 90 || runway.direction2.windAngle < 90
})

console.log(bestRunways)

bestRunways.forEach(runway => {
// Set the favourable level to 1 if the wind angle is less than 90 and 2 if the wind angle is less than 45 degrees
if (runway.direction1.windAngle! < 90)
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/WeatherElementLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const WeatherElementLayout: ParentComponent<ParsedWeatherElementLayoutProps> = p
setTriggerPing(true)
setTimeout(() => {
setTriggerPing(false)
}, 2000)
}, 3000)
}

createEffect<string | undefined>(previous => {
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
layout: '1fr auto',
},
animation: {
'ping-large': 'ping-large 1s cubic-bezier(0, 0, 0.2, 1) 2',
'ping-large': 'ping-large 1s cubic-bezier(0, 0, 0.2, 1) 3',
},
},
},
Expand Down

0 comments on commit 4563284

Please sign in to comment.