-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathanalyzer_util.h
94 lines (68 loc) · 2.28 KB
/
analyzer_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef _ANALYZER_UTIL
#define _ANALYZER_UTIL
#define _USE_MATH_DEFINES
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory>
#include <string>
// TODO: work out why _USE_MATH_DEFINES is not working
#ifndef M_PI
# define M_PI 3.14159265358979323846 /* pi */
#endif
double earthradius();
double wrap_valid_longitude(const double longitude);
// http://www.movable-type.co.uk/scripts/latlong.html
void gps_newpos(const double orig_lat, const double orig_lon, const double bearing, const double distance, double &dest_lat, double &dest_lon);
// origin_lat in degrees
// origin_lon in degrees
// bearing in degrees
// distance in metres
void gps_offset(double orig_lat, double orig_lon, double east, double north, double &dest_lat, double &dest_lon);
double altitude_from_pressure_delta(
double gnd_abs_press,
double gnd_temp,
double press_abs,
double temp);
// from: http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
template<typename ... Args>
std::string
string_format( const char* format, const Args ... args )
{
int32_t size = snprintf( nullptr, 0, format, args ... );
if (size < 0) {
::fprintf(stderr, "snprintf error (%d): %s\n", size, strerror(errno));
abort();
}
size += 1; // Extra space for '\0'
std::unique_ptr<char[]> buf( new char[ size ] );
snprintf( buf.get(), size, format, args ... );
return std::string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside
}
template<typename ... Args>
std::string
string_format( const std::string format, const Args ... args )
{
return string_format(format.c_str(), args ... );
}
#ifndef streq
#define streq(x,y) (!strcmp(x,y))
#endif
bool strieq(const char *x, const char *y);
// inline float deg_to_rad(const float deg) {
// return deg/M_PI * 180;
// }
// inline float rad_to_deg(const float rad) {
// return rad*180/M_PI;
// }
#define deg_to_rad(x) ((x)*M_PI/180.0f)
#define rad_to_deg(x) ((x)*180.0f/M_PI)
#define is_zero(x) (x < 0.00001)
#define is_equal(x, y) (is_zero(fabs((x)-(y))))
void format_timestamp(char *buf, uint8_t buflen, uint64_t T);
uint64_t now();
double vec_len(double vec[3]);
#define UNUSED __attribute__ ((unused))
#endif // _ANALYZER_UTIL