coordinateconversion.hh 1.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef RADIX_RADIXGEO_COORDINATECONVERSION_HH_
#define RADIX_RADIXGEO_COORDINATECONVERSION_HH_

#include "radixcore/visibility.hh"

#include <sstream>
#include <stdexcept>
namespace radix
{
class RADIX_PUBLIC CoordinateConversion
{
 public:
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  /**
   * @brief validate Validates coordinate
   * @param latitude latitude coordinate
   * @param longitude longitude coordinate
   * Throws std::out_of_range exception if latitude is outside [-90.,90.] or
   * longitude must be [-180,180).
   */
  template <typename data_type>
  static void validate(data_type latitude, data_type longitude);
  /**
   * @brief validate Validates coordinate
   * @parm point where point.first is latitutde and point.second is longitude
   * Throws std::out_of_range exception if latitude is outside [-90.,90.] or
   * longitude must be [-180,180).
   */

  template <typename data_type>
  static void validate(const std::pair<data_type, data_type>& point);
31
32

};  // class CoordinateConversion
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

template <typename data_type>
void CoordinateConversion::validate(
    const std::pair<data_type, data_type>& point)
{
  CoordinateConversion::validate(point.first, point.second);
}

template <typename data_type>
void CoordinateConversion::validate(data_type latitude, data_type longitude)
{
  if (latitude < data_type(-90.0) || latitude > data_type(90.0) ||
      longitude < data_type(-180.0) || longitude >= data_type(180.0))
  {
    std::ostringstream oss;
    oss << "Invalid coordinate [" << latitude << "," << longitude
        << "].\nLatitude must be [-90,90] and longitude must be "
           "[-180,180).";
    throw std::out_of_range(oss.str());
  }
}
54
55
}  // namespace radix
#endif /** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */