Loading...
Searching...
No Matches
wind_dir.c File Reference

The compass direction a wind is blowing from, as a bearing and as a sideways component. More...

#include "weather/wind_dir.h"
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>

Macros

#define POINT_COUNT   16
 How many compass points a direction can name, from N through NNW.

Functions

static bool same_point (const char *a, const char *b)
 Whether two compass abbreviations are the same, ignoring case.
static int sin_milli (int degrees)
 Sine in thousandths, from a table every 15 degrees with the gaps interpolated.
int wind_bearing (const char *dir)
 The bearing a 16-point compass abbreviation stands for.
int wind_lean (int bearing)
 The east-west component of a wind, as a signed proportion.

Detailed Description

The compass direction a wind is blowing from, as a bearing and as a sideways component.

Function Documentation

◆ same_point()

bool same_point ( const char * a,
const char * b )
static

Whether two compass abbreviations are the same, ignoring case.

Parameters
aThe first abbreviation.
bThe second abbreviation.
Returns
Whether they match, case insensitive.

◆ sin_milli()

int sin_milli ( int degrees)
static

Sine in thousandths, from a table every 15 degrees with the gaps interpolated.

The watch has a trig lookup but this file is pure core and cannot reach it, and pulling float maths in for one component would cost more than the table does. Straight lines between fifteen-degree stops land within a percent of a real sine, which is finer than a caller working in whole pixels or whole percent can use.

Parameters
degreesThe angle to take the sine of. Wrapped into 0 to 359 first, negative values included.
Returns
The sine of the angle, times 1000.