14
14
#include < algorithm>
15
15
16
16
#include < boost/geometry/algorithms/equals.hpp>
17
- #include < boost/geometry/algorithms/transform.hpp>
18
- #include < boost/geometry/algorithms/within.hpp>
19
- #include < boost/geometry/geometries/box.hpp>
20
17
#include < boost/geometry/core/point_type.hpp>
18
+ #include < boost/geometry/core/cs.hpp>
19
+ #include < boost/geometry/algorithms/length.hpp>
20
+ #include < boost/geometry/algorithms/line_interpolate.hpp>
21
+ #include < boost/geometry/strategies/cartesian/line_interpolate.hpp>
22
+ #include < boost/geometry/strategies/geographic/line_interpolate.hpp>
23
+ #include < boost/geometry/strategies/spherical/line_interpolate.hpp>
21
24
22
25
#include < boost/geometry/extensions/random/strategies/uniform_point_distribution.hpp>
23
- #include < boost/geometry/extensions/random/strategies/cartesian/uniform_point_distribution_segment.hpp>
24
- #include < boost/geometry/extensions/random/strategies/spherical/edwilliams_avform_intermediate.hpp>
25
26
26
27
namespace boost { namespace geometry
27
28
{
@@ -32,13 +33,50 @@ template
32
33
<
33
34
typename Point,
34
35
typename DomainGeometry,
35
- typename SegmentStrategy = services::default_strategy
36
- <
37
- typename point_type<DomainGeometry>::type,
38
- model::segment< typename point_type <DomainGeometry>::type>
39
- >
36
+ typename InterpolationStrategy =
37
+ typename strategy::line_interpolate::services::default_strategy
38
+ <
39
+ typename cs_tag <DomainGeometry>::type
40
+ >::type
40
41
>
41
- class uniform_linear
42
+ struct uniform_linear_single
43
+ {
44
+ uniform_linear_single (DomainGeometry const & g) {}
45
+ bool equals (DomainGeometry const & l_domain,
46
+ DomainGeometry const & r_domain,
47
+ uniform_linear_single const & r_strategy) const
48
+ {
49
+ return boost::geometry::equals (l_domain, r_domain);
50
+ }
51
+
52
+ template <typename Gen>
53
+ Point apply (Gen& g, DomainGeometry const & d)
54
+ {
55
+ typedef typename select_most_precise
56
+ <
57
+ double ,
58
+ typename coordinate_type<Point>::type
59
+ >::type sample_type;
60
+ std::uniform_real_distribution<sample_type> dist (0 , length (d));
61
+ sample_type r = dist (g);
62
+ Point p;
63
+ boost::geometry::line_interpolate (d, r, p);
64
+ return p;
65
+ }
66
+ void reset (DomainGeometry const &) {};
67
+ };
68
+
69
+ template
70
+ <
71
+ typename Point,
72
+ typename DomainGeometry,
73
+ typename InterpolationStrategy =
74
+ typename strategy::line_interpolate::services::default_strategy
75
+ <
76
+ typename cs_tag<DomainGeometry>::type
77
+ >::type
78
+ >
79
+ class uniform_linear_multi
42
80
{
43
81
private:
44
82
typedef typename default_length_result<DomainGeometry>::type length_type;
@@ -47,7 +85,7 @@ class uniform_linear
47
85
std::vector<domain_point_type> point_cache;
48
86
std::vector<length_type> accumulated_lengths;
49
87
public:
50
- uniform_linear (DomainGeometry const & g)
88
+ uniform_linear_multi (DomainGeometry const & g)
51
89
{
52
90
std::size_t i = 0 ;
53
91
point_cache.push_back (*segments_begin (g)->first );
@@ -67,7 +105,7 @@ class uniform_linear
67
105
}
68
106
bool equals (DomainGeometry const & l_domain,
69
107
DomainGeometry const & r_domain,
70
- uniform_linear const & r_strategy) const
108
+ uniform_linear_multi const & r_strategy) const
71
109
{
72
110
if (r_strategy.skip_list .size () != skip_list.size ()
73
111
|| r_strategy.point_cache .size () != point_cache.size ())
@@ -90,6 +128,7 @@ class uniform_linear
90
128
double ,
91
129
typename coordinate_type<Point>::type
92
130
>::type sample_type;
131
+ typedef model::segment<domain_point_type> segment;
93
132
std::uniform_real_distribution<sample_type> dist (0 , accumulated_lengths.back ());
94
133
sample_type r = dist (g);
95
134
std::size_t i = std::distance (
@@ -100,20 +139,38 @@ class uniform_linear
100
139
std::size_t offset = std::distance (
101
140
skip_list.begin (),
102
141
std::lower_bound (skip_list.begin (), skip_list.end (), i));
103
-
104
- return SegmentStrategy::template map
105
- <
106
- sample_type,
107
- domain_point_type
108
- >(point_cache[ i + offset - 1 ], point_cache[ i + offset ],
109
- ( r - accumulated_lengths[ i - 1 ]) /
110
- ( accumulated_lengths[ i ] - accumulated_lengths[ i - 1 ] ));
142
+ Point p;
143
+ boost::geometry::line_interpolate (
144
+ segment (point_cache[ i + offset - 1 ], point_cache[ i + offset ]),
145
+ r - accumulated_lengths[ i - 1 ],
146
+ p);
147
+ return p;
111
148
}
112
149
void reset (DomainGeometry const &) {};
113
150
};
114
151
115
152
namespace services {
116
153
154
+ template
155
+ <
156
+ typename Point,
157
+ typename DomainGeometry,
158
+ int Dim,
159
+ typename CsTag
160
+ >
161
+ struct default_strategy
162
+ <
163
+ Point,
164
+ DomainGeometry,
165
+ segment_tag,
166
+ single_tag,
167
+ Dim,
168
+ CsTag
169
+ > : public uniform_linear_single<Point, DomainGeometry> {
170
+ typedef uniform_linear_single<Point, DomainGeometry> base;
171
+ using base::base;
172
+ };
173
+
117
174
template
118
175
<
119
176
typename Point,
@@ -130,8 +187,8 @@ struct default_strategy
130
187
MultiOrSingle,
131
188
Dim,
132
189
CsTag
133
- > : public uniform_linear <Point, DomainGeometry> {
134
- typedef uniform_linear <Point, DomainGeometry> base;
190
+ > : public uniform_linear_multi <Point, DomainGeometry> {
191
+ typedef uniform_linear_multi <Point, DomainGeometry> base;
135
192
using base::base;
136
193
};
137
194
0 commit comments