1414#include < algorithm>
1515
1616#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>
2017#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>
2124
2225#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>
2526
2627namespace boost { namespace geometry
2728{
@@ -32,13 +33,50 @@ template
3233<
3334 typename Point,
3435 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
4041>
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
4280{
4381private:
4482 typedef typename default_length_result<DomainGeometry>::type length_type;
@@ -47,7 +85,7 @@ class uniform_linear
4785 std::vector<domain_point_type> point_cache;
4886 std::vector<length_type> accumulated_lengths;
4987public:
50- uniform_linear (DomainGeometry const & g)
88+ uniform_linear_multi (DomainGeometry const & g)
5189 {
5290 std::size_t i = 0 ;
5391 point_cache.push_back (*segments_begin (g)->first );
@@ -67,7 +105,7 @@ class uniform_linear
67105 }
68106 bool equals (DomainGeometry const & l_domain,
69107 DomainGeometry const & r_domain,
70- uniform_linear const & r_strategy) const
108+ uniform_linear_multi const & r_strategy) const
71109 {
72110 if (r_strategy.skip_list .size () != skip_list.size ()
73111 || r_strategy.point_cache .size () != point_cache.size ())
@@ -90,6 +128,7 @@ class uniform_linear
90128 double ,
91129 typename coordinate_type<Point>::type
92130 >::type sample_type;
131+ typedef model::segment<domain_point_type> segment;
93132 std::uniform_real_distribution<sample_type> dist (0 , accumulated_lengths.back ());
94133 sample_type r = dist (g);
95134 std::size_t i = std::distance (
@@ -100,20 +139,38 @@ class uniform_linear
100139 std::size_t offset = std::distance (
101140 skip_list.begin (),
102141 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;
111148 }
112149 void reset (DomainGeometry const &) {};
113150};
114151
115152namespace services {
116153
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+
117174template
118175<
119176 typename Point,
@@ -130,8 +187,8 @@ struct default_strategy
130187 MultiOrSingle,
131188 Dim,
132189 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;
135192 using base::base;
136193};
137194
0 commit comments