|
10 | 10 | #ifndef BOOST_GEOMETRY_PROJECTIONS_CODE_HPP
|
11 | 11 | #define BOOST_GEOMETRY_PROJECTIONS_CODE_HPP
|
12 | 12 |
|
13 |
| - |
14 |
| -#include <algorithm> |
| 13 | +#include <cstdint> |
15 | 14 |
|
16 | 15 | #include <boost/geometry/srs/projections/dpar.hpp>
|
17 | 16 |
|
18 |
| - |
19 | 17 | namespace boost { namespace geometry { namespace projections
|
20 | 18 | {
|
21 | 19 |
|
22 |
| - |
23 | 20 | #ifndef DOXYGEN_NO_DETAIL
|
24 | 21 | namespace detail
|
25 | 22 | {
|
26 | 23 |
|
| 24 | + template <std::size_t MaxParams, bool HasTowgs84 = true> |
27 | 25 | struct code_element
|
28 | 26 | {
|
| 27 | + union parameter_variant |
| 28 | + { |
| 29 | + bool b; |
| 30 | + int i; |
| 31 | + double v; |
| 32 | + //spheroid |
| 33 | + //nadgrids, |
| 34 | + //towgs84 |
| 35 | + }; |
| 36 | + |
29 | 37 | int code;
|
30 |
| - srs::dpar::parameters<> parameters; |
| 38 | + std::int8_t parameter_count; |
| 39 | + std::int8_t towgs84_size {0}; |
| 40 | + // Not bundling the following together into a struct to avoid 8-byte-alignment. |
| 41 | + std::int8_t parameter_variant_tags[MaxParams]; |
| 42 | + std::int16_t parameter_ids[MaxParams]; |
| 43 | + parameter_variant parameters[MaxParams]; |
| 44 | + double towgs84_data[7]; |
31 | 45 | };
|
32 | 46 |
|
33 |
| - struct code_element_less |
| 47 | + template <std::size_t MaxParams> |
| 48 | + struct code_element<MaxParams, false> |
34 | 49 | {
|
35 |
| - inline bool operator()(code_element const& l, code_element const& r) const |
| 50 | + union parameter_variant |
36 | 51 | {
|
37 |
| - return l.code < r.code; |
| 52 | + bool b; |
| 53 | + int i; |
| 54 | + double v; |
| 55 | + }; |
| 56 | + |
| 57 | + int code; |
| 58 | + std::int8_t parameter_count; |
| 59 | + std::int8_t parameter_variant_tags[MaxParams]; |
| 60 | + std::int16_t parameter_ids[MaxParams]; |
| 61 | + parameter_variant parameters[MaxParams]; |
| 62 | + }; |
| 63 | + |
| 64 | + template <bool HasTowgs84 = true> |
| 65 | + struct code_element_to_towgs84 |
| 66 | + { |
| 67 | + template <std::size_t MaxParams> |
| 68 | + static void apply(code_element<MaxParams, true> const& e, |
| 69 | + srs::dpar::parameters<double>& out) |
| 70 | + { |
| 71 | + using p = srs::dpar::parameter<double>; |
| 72 | + out(p(srs::dpar::name_towgs84::towgs84, |
| 73 | + srs::detail::towgs84<double>(e.towgs84_data, e.towgs84_data + e.towgs84_size))); |
38 | 74 | }
|
39 | 75 | };
|
40 | 76 |
|
41 |
| - template<typename RandIt> |
42 |
| - inline RandIt binary_find_code_element(RandIt first, RandIt last, int code) |
| 77 | + template <> |
| 78 | + struct code_element_to_towgs84<false> |
| 79 | + { |
| 80 | + template <std::size_t MaxParams> |
| 81 | + static void apply(code_element<MaxParams, false> const&, srs::dpar::parameters<double>&) {} |
| 82 | + }; |
| 83 | + |
| 84 | + |
| 85 | + template <std::size_t MaxParams, bool HasTowgs84> |
| 86 | + inline srs::dpar::parameters<> |
| 87 | + code_element_to_dpar_parameters(code_element<MaxParams, HasTowgs84> const& e) |
43 | 88 | {
|
44 |
| - code_element_less comp; |
45 |
| - code_element value; |
46 |
| - value.code = code; |
47 |
| - first = std::lower_bound(first, last, value, comp); |
48 |
| - return first != last && !comp(value, *first) ? first : last; |
| 89 | + using namespace srs::dpar; |
| 90 | + using p = srs::dpar::parameter<double>; |
| 91 | + srs::dpar::parameters<> out; |
| 92 | + out.reserve(e.parameter_count); |
| 93 | + for (int i = 0; i < e.parameter_count; ++i) |
| 94 | + { |
| 95 | + auto const& id = e.parameter_ids[i]; |
| 96 | + auto const& pv = e.parameters[i]; |
| 97 | + auto const& tag = e.parameter_variant_tags[i]; |
| 98 | + if (id == -1) |
| 99 | + { |
| 100 | + out(p()); |
| 101 | + } |
| 102 | + else if (id < static_cast<int>(name_r::alpha)) // f |
| 103 | + { |
| 104 | + out(p(static_cast<name_f>(id), pv.v)); |
| 105 | + } |
| 106 | + else if (id < static_cast<int>(name_i::aperture)) // r |
| 107 | + { |
| 108 | + out(p(static_cast<name_r>(id), pv.v)); |
| 109 | + } |
| 110 | + else if (id < static_cast<int>(name_be::czech)) // i |
| 111 | + { |
| 112 | + out(p(static_cast<name_i>(id), pv.i)); |
| 113 | + } |
| 114 | + else if (id < static_cast<int>(name_datum::datum)) // be |
| 115 | + { |
| 116 | + out(p(static_cast<name_be>(id), pv.b)); |
| 117 | + } |
| 118 | + else if (id == static_cast<int>(name_datum::datum)) //datum |
| 119 | + { |
| 120 | + out(p(name_datum::datum, static_cast<value_datum>(pv.i))); |
| 121 | + } |
| 122 | + else if ( id == static_cast<int>(name_ellps::ellps)) //ellps |
| 123 | + { |
| 124 | + out(p(name_ellps::ellps, static_cast<value_ellps>(pv.i))); |
| 125 | + } |
| 126 | + // no occurence of ellps with spheroid in arr |
| 127 | + // no occurence of mode in arr |
| 128 | + // no occurence of nadgrids in arr |
| 129 | + // no occurence of orient in arr |
| 130 | + else if (id == static_cast<name_pm>(name_pm::pm)) //pm |
| 131 | + { |
| 132 | + if (tag == 1) |
| 133 | + { |
| 134 | + out(p(name_pm::pm, static_cast<value_pm>(pv.i))); |
| 135 | + } |
| 136 | + else //if tag == 2 |
| 137 | + { |
| 138 | + out(p(name_pm::pm, pv.v)); |
| 139 | + } |
| 140 | + } |
| 141 | + else if (id < static_cast<int>(name_sweep::sweep)) // proj |
| 142 | + { |
| 143 | + out(p(static_cast<name_proj>(id), static_cast<value_proj>(pv.i))); |
| 144 | + } |
| 145 | + else if (id == static_cast<int>(name_sweep::sweep)) // sweep |
| 146 | + { |
| 147 | + out(p(name_sweep::sweep, static_cast<value_sweep>(pv.i))); |
| 148 | + } |
| 149 | + else if (id == static_cast<int>(name_towgs84::towgs84)) //towgs84 |
| 150 | + { |
| 151 | + code_element_to_towgs84<HasTowgs84>::apply(e, out); |
| 152 | + } |
| 153 | + // no occurence of axis in arr |
| 154 | + else if (id == static_cast<int>(name_units::units)) //units |
| 155 | + { |
| 156 | + out(p(name_units::units, static_cast<value_units>(pv.i))); |
| 157 | + } |
| 158 | + // no occurence of vunits in arr |
| 159 | + } |
| 160 | + return out; |
49 | 161 | }
|
50 | 162 |
|
51 | 163 | }
|
|
0 commit comments