owlps/owlps-positioner/src/posutil.hh

107 lines
2.7 KiB
C++
Raw Normal View History

/*
* This file is part of the Owl Positioning System (OwlPS).
* OwlPS is a project of the University of Franche-Comté
* (Université de Franche-Comté), France.
*/
#ifndef _OWLPS_POSITIONING_POSUTIL_HH_
#define _OWLPS_POSITIONING_POSUTIL_HH_
class Measurement ;
#include <boost/tr1/unordered_map.hpp>
#include <boost/algorithm/string/case_conv.hpp>
/// Utilitary class
class PosUtil
{
public:
/// The speed of light, in m/s
static const unsigned long LIGHT_SPEED = 299792458 ;
2011-07-13 14:56:06 +02:00
/** @name Maths */
//@{
2012-04-30 09:55:32 +02:00
/// Returns the radian value of \em degrees
static double deg2rad(const double &degrees) ;
/// Returns the degree value of \em radians
2011-07-13 14:56:06 +02:00
static double rad2deg(const double &radians) ;
/// Checks if \em value is in the interval [center-width;center+width]
static bool is_in_interval(float center, float bound, float value) ;
2011-07-13 14:56:06 +02:00
//@}
/** @name Measurements */
//@{
/// Mutually completes two Measurement lists with missing APs
static void complete_with_dummy_measurements(
std::tr1::unordered_map<std::string, Measurement> &measurements1,
std::tr1::unordered_map<std::string, Measurement> &measurements2) ;
/// Computes the similarity of two Measurement lists
static float similarity(
std::tr1::unordered_map<std::string, Measurement> &measurements1,
std::tr1::unordered_map<std::string, Measurement> &measurements2) ;
//@}
/** @name Wi-Fi */
//@{
/// Converts a Wi-Fi channel to the corresponding frequency in Hz
static unsigned long wifi_channel_to_hz(const unsigned long &channel) ;
//@}
/** @name Strings */
//@{
static void to_upper(std::string &str) ;
static void assert_uppercase(const std::string &str) ;
static std::string int_to_mac(const uint32_t source) ;
//@}
} ;
/* *** Maths *** */
/**
* This function checks if \em value belongs to the symmetrical interval
* [center-bound;center+bound].
*
* @arg center The center of the interval.
* @arg bound Half the width of the interval.
* @arg value The value to check the presence in the interval.
*
* @returns \em true if value belongs to the interval.
* @returns \em false if value does not belong to the interval.
*/
inline bool PosUtil::
is_in_interval(float center, float bound, float value)
{
assert(bound > 0) ;
float interval_min = center - bound ;
float interval_max = center + bound ;
return interval_min <= value && value <= interval_max ;
}
/* *** Strings *** */
inline void PosUtil::to_upper(std::string &str)
{
boost::to_upper(str) ;
}
inline void PosUtil::assert_uppercase(const std::string &str)
{
#ifndef NDEBUG
std::string str_up(str) ;
to_upper(str_up) ;
assert(str_up == str) ;
#endif // NDEBUG
}
#endif // _OWLPS_POSITIONING_POSUTIL_HH_