Skip to content

Commit bb8a7c5

Browse files
committed
Refactor epsg, esri, iau2000 for faster compile times.
1 parent 787c1af commit bb8a7c5

File tree

4 files changed

+7296
-7222
lines changed

4 files changed

+7296
-7222
lines changed

include/boost/geometry/srs/projections/code.hpp

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define BOOST_GEOMETRY_PROJECTIONS_CODE_HPP
1212

1313

14-
#include <algorithm>
14+
#include <cmath>
1515

1616
#include <boost/geometry/srs/projections/dpar.hpp>
1717

@@ -24,30 +24,93 @@ namespace boost { namespace geometry { namespace projections
2424
namespace detail
2525
{
2626

27+
struct code_parameter {
28+
constexpr code_parameter() : id{-1}, val_i{-1} {}
29+
constexpr code_parameter(srs::dpar::name_f n, double v) : id{n}, val_d{v}, var_type{2} {}
30+
constexpr code_parameter(srs::dpar::name_r n, double v) : id{n}, val_d{v}, var_type{2} {}
31+
constexpr code_parameter(srs::dpar::name_i n, int v) : id{n}, val_i{v} {}
32+
constexpr code_parameter(srs::dpar::name_be n, bool v = true) : id{n}, val_b{v} {}
33+
constexpr code_parameter(srs::dpar::name_datum n, srs::dpar::value_datum v) : id{n}, val_i{v} {}
34+
constexpr code_parameter(srs::dpar::value_datum v) : id{srs::dpar::datum}, val_i{v} {}
35+
constexpr code_parameter(srs::dpar::name_ellps n, srs::dpar::value_ellps v) : id{n}, val_i{v} {}
36+
constexpr code_parameter(srs::dpar::value_ellps v) : id{srs::dpar::ellps}, val_i{v} {}
37+
constexpr code_parameter(srs::dpar::name_mode n, srs::dpar::value_mode v) : id{n}, val_i{v} {}
38+
constexpr code_parameter(srs::dpar::value_mode v) : id{srs::dpar::mode}, val_i{v} {}
39+
constexpr code_parameter(srs::dpar::name_orient n, srs::dpar::value_orient v) : id{srs::dpar::mode}, val_i{v} {}
40+
constexpr code_parameter(srs::dpar::value_orient v) : id{srs::dpar::orient}, val_i{v} {}
41+
constexpr code_parameter(srs::dpar::name_pm n, srs::dpar::value_pm v) : id{n}, val_i{v} {}
42+
constexpr code_parameter(srs::dpar::value_pm v) : id{srs::dpar::pm}, val_i{v} {}
43+
constexpr code_parameter(srs::dpar::name_pm n, double v) : id{n}, val_d{v}, var_type{2} {}
44+
constexpr code_parameter(srs::dpar::name_proj n, srs::dpar::value_proj v) : id{n}, val_i{v} {}
45+
constexpr code_parameter(srs::dpar::value_proj v) : id{srs::dpar::proj}, val_i{v} {}
46+
constexpr code_parameter(srs::dpar::name_sweep n, srs::dpar::value_sweep v) : id{n}, val_i{v} {}
47+
constexpr code_parameter(srs::dpar::value_sweep v) : id{srs::dpar::sweep}, val_i{v} {}
48+
constexpr code_parameter(srs::dpar::name_units n, srs::dpar::value_units v) : id{n}, val_i{v} {}
49+
constexpr code_parameter(srs::dpar::value_units v) : id{srs::dpar::units}, val_i{v} {}
50+
int id;
51+
union {
52+
bool val_b;
53+
int val_i;
54+
double val_d;
55+
};
56+
int var_type = 1;
57+
inline explicit operator srs::dpar::parameter<double>() const {
58+
using namespace srs::dpar;
59+
using p = parameter<double>;
60+
if (id == -1) return p{};
61+
if (id <= y_0) return p(static_cast<name_f>(id), val_d);
62+
if (id <= tilt) return p(static_cast<name_r>(id), val_d);
63+
if (id <= zone) return p(static_cast<name_i>(id), val_i);
64+
if (id <= south) return p(static_cast<name_be>(id), val_b);
65+
if (id == datum) return p(static_cast<name_datum>(id), static_cast<value_datum>(val_i));
66+
if (id == ellps) return p(static_cast<name_ellps>(id), static_cast<value_ellps>(val_i));
67+
if (id == mode) return p(static_cast<name_mode>(id), static_cast<value_mode>(val_i));
68+
if (id == orient) return p(static_cast<name_orient>(id), static_cast<value_orient>(val_i));
69+
if (id == pm && var_type == 1) return p(static_cast<name_pm>(id), static_cast<value_pm>(val_i));
70+
if (id == pm && var_type == 2) return p(static_cast<name_pm>(id), val_d);
71+
if (id <= proj) return p(static_cast<name_proj>(id), static_cast<value_proj>(val_i));
72+
if (id == name_sweep::sweep) return p(static_cast<name_sweep>(id), static_cast<value_sweep>(val_i));
73+
if (id == units) return p(static_cast<name_units>(id), static_cast<value_units>(val_i));
74+
return p{};
75+
}
76+
};
77+
2778
struct code_element
2879
{
80+
constexpr code_element(int code,
81+
std::array<code_parameter, 13> const& parameters,
82+
std::array<double, 7> towgs84 =
83+
{INFINITY, INFINITY, INFINITY, INFINITY, INFINITY, INFINITY, INFINITY})
84+
: code{code}, parameters{parameters}, towgs84{towgs84} {}
85+
constexpr code_element() : code{-1}, parameters{}, towgs84{} {}
2986
int code;
30-
srs::dpar::parameters<> parameters;
87+
std::array<code_parameter, 13> parameters;
88+
std::array<double, 7> towgs84;
89+
srs::dpar::parameters<double> to_parameters() const {
90+
srs::dpar::parameters<double> out;
91+
bool towgs84_to_be_inserted = towgs84[0] != INFINITY;
92+
for (const auto& p : parameters)
93+
{
94+
if (towgs84_to_be_inserted && (p.id == srs::dpar::units || p.id == srs::dpar::no_defs))
95+
{
96+
towgs84_to_be_inserted = false;
97+
out(srs::dpar::towgs84, towgs84);
98+
}
99+
out.add(p);
100+
if (p.id == srs::dpar::no_defs) break;
101+
}
102+
return out;
103+
}
31104
};
32105

33106
struct code_element_less
34107
{
35-
inline bool operator()(code_element const& l, code_element const& r) const
108+
inline bool operator()(code_element const& l, int code) const
36109
{
37-
return l.code < r.code;
110+
return l.code < code;
38111
}
39112
};
40113

41-
template<typename RandIt>
42-
inline RandIt binary_find_code_element(RandIt first, RandIt last, int code)
43-
{
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;
49-
}
50-
51114
}
52115
#endif // DOXYGEN_NO_DETAIL
53116

0 commit comments

Comments
 (0)