3#ifndef BOAT_GEOMETRY_ALGORITHM_HPP
4#define BOAT_GEOMETRY_ALGORITHM_HPP
6#include <boat/detail/numbers.hpp>
8#include <boost/geometry.hpp>
17 for (
auto edge : boost::geometry::box_view{mbr} | std::views::pairwise) {
18 auto a = std::get<0>(edge), b = std::get<1>(edge);
19 for (
auto i : std::views::iota(0uz, edge_points)) {
20 auto t = double(i) / edge_points;
22 std::lerp(a.x(), b.x(), t), std::lerp(a.y(), b.y(), t));
25 auto a = mbr.min_corner(), b = mbr.max_corner();
26 for (
auto i : std::views::iota(0uz, area_points))
28 std::lerp(a.x(), b.x(), frac(i * numbers::inv_phi)),
29 std::lerp(a.y(), b.y(), (i + .5) / area_points));
33inline auto buffer(
double distance,
size_t num_points)
36 namespace sb = boost::geometry::strategy::buffer;
37 using point_circle = std::conditional_t<
39 boost::geometry::cs_tag_t<T>,
40 boost::geometry::geographic_tag>,
41 sb::geographic_point_circle<>,
44 boost::geometry::buffer(
47 sb::distance_symmetric{distance},
49 sb::join_round{num_points},
50 sb::end_round{num_points},
51 point_circle{num_points});
52 return std::move(out.at(0));
57constexpr auto meter = overloaded{
58 [] {
return numbers::radian / numbers::earth::mean_radius; },
59 [](
this auto&& self,
double lat) {
60 auto den = std::cos(lat * numbers::degree);
61 return den ? self() / den : 0.;
68 [](
this auto&& self,
multi auto&& v) ->
void {
69 std::ranges::for_each(v, self);
71 [](
this auto&& self,
dynamic auto&& v) ->
void {
78 visitor([&](
single auto&& v) { boost::geometry::for_each_point(v, fn); })(
85 auto [y, reflected] = reflect(p.y(), -90., 90.);
86 return {boat::wrap(p.x() + 180 * reflected, -180., 180.), y};
93 p.x() + eastward *
meter(p.y()), p.y() + northward *
meter()});
Definition vocabulary.hpp:34
Definition vocabulary.hpp:43
Definition vocabulary.hpp:40
Definition vocabulary.hpp:49
Definition vocabulary.hpp:58
Definition vocabulary.hpp:28
Definition algorithm.hpp:10
void for_each_point(tagged auto const &geom, auto fn)
Definition algorithm.hpp:76
geographic::point wrap(geographic::point const &p)
Wraps at the poles and antimeridian.
Definition algorithm.hpp:83
multi_point auto box_interpolate(T const &mbr, size_t edge_points, size_t area_points)
Definition algorithm.hpp:14
geographic::point add_meters(geographic::point const &p, double eastward, double northward)
Definition algorithm.hpp:90
auto buffer(double distance, size_t num_points)
Definition algorithm.hpp:33
auto visitor(auto... fn)
Definition algorithm.hpp:64
constexpr auto meter
Approximate degrees per meter of latitude, or longitude at a given latitude.
Definition algorithm.hpp:57
model::multi_polygon< polygon > multi_polygon
Definition vocabulary.hpp:70
model::multi_point< point > multi_point
Definition vocabulary.hpp:68
model::d2::point_xy< double, cs::geographic< boost::geometry::degree > > point
Definition vocabulary.hpp:65