constants.hh 2.16 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * File:   constants.hh
 * Author: Jordan P. Lefebvre
 *
 * Created on August 13, 2012, 8:26 PM
 */

#ifndef RADIX_RADIXMATH_CONSTANTS_H
9
#define RADIX_RADIXMATH_CONSTANTS_H
10
11
#include <cmath>
#include <limits>
12
13

#include "radixdl/visibility.hh"
14
namespace radix {
15
16
17
18
19
20
/**
 * Type def double precision
 */
typedef unsigned short index_t;
typedef double Real;
const Real EARTH_RADIUS_MEAN = 6371200.0;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const Real wgs84_minor       = 6356752.314245;
const Real kEpsilon          = 1.0E-12;
const Real lookAheadEpsilon  = 1.0E-9;
const Real halfKEpsilon      = 0.5 * kEpsilon;
const Real kHugeValue        = 1.0E10;
const Real maxReal           = std::numeric_limits<Real>::max();
const Real minReal           = std::numeric_limits<Real>::min();
const Real PI               = 2 * std::acos(Real(0));  // 3.1415926535897932384;
const Real TWO_PI           = PI * 2;                  // 6.2831853071795864769;
const Real PI_BELOW_180     = 180 / PI;
const Real PI_ON_180        = PI / 180;    // 0.0174532925199432957;
const Real invPI            = 1 / PI;      // 0.3183098861837906715;
const Real invTWO_PI        = 1 / TWO_PI;  // 0.1591549430918953358;
const Real infinity         = std::numeric_limits<Real>::infinity();
const Real sqrtHALF         = std::sqrt(Real(0.5));
const Real sqrtTWO          = std::sqrt(Real(2.0));
const Real sqrtTHREE        = std::sqrt(Real(3.0));
const Real DAYS_PER_YEAR    = 365.25;
39
const Real SECONDS_PER_HOUR = 3600.0;
40
const Real METERS_PER_MILE  = 1609.344;
41
42
43
44
/**
 * Type def unsigned long to Identifier
 */
typedef unsigned long Identifier;
45

46
47
48
49
50
51
52
/**
 * @function clamp
 * @param x 1d point in space
 * @param min
 * @param max
 * @return
 */
53
54
inline Real RADIX_PUBLIC clamp(const Real x, const Real min, const Real max) {
  return (x < min ? min : (x > max ? max : x));
55
}
56
57
inline bool RADIX_PUBLIC isWithin(Real x, Real y, Real within = kEpsilon) {
  return std::abs(x - y) <= within;
58
59
60
61
62
63
64
}
/**
 * Determine if the two values are within kepsilon of one-another
 * @param x
 * @param y
 * @return true, iff abs(x-y) <= kEpsilon
 */
65
66
inline bool RADIX_PUBLIC isWithinKEpsilon(Real x, Real y) {
  return isWithin(x, y, kEpsilon);
67
}
68

69
70
}  // namespace radix
#endif /* RADIX_RADIXMATH_CONSTANTS_H */