2
2
3
3
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
4
4
5
+ // Contributed and/or modified by Tinko Bartels,
6
+ // as part of Google Summer of Code 2019 program.
7
+
5
8
// Use, modification and distribution is subject to the Boost Software License,
6
9
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7
10
// http://www.boost.org/LICENSE_1_0.txt)
8
11
9
- #ifndef BOOST_GEOMETRY_EXTENSIONS_RANDOM_STRATEGIES_AGNOSTIC_UNIFORM_CONVEX_FAN_HPP
10
- #define BOOST_GEOMETRY_EXTENSIONS_RANDOM_STRATEGIES_AGNOSTIC_UNIFORM_CONVEX_FAN_HPP
12
+ #ifndef BOOST_GEOMETRY_EXTENSIONS_RANDOM_STRATEGIES_AGNOSTIC_UNIFORM_CONVEX_POLYGON_SAMPLER_HPP
13
+ #define BOOST_GEOMETRY_EXTENSIONS_RANDOM_STRATEGIES_AGNOSTIC_UNIFORM_CONVEX_POLYGON_SAMPLER_HPP
11
14
12
15
#include < random>
13
16
#include < vector>
14
17
#include < cstdlib>
15
18
#include < cmath>
16
19
20
+ #include < boost/range/size.hpp>
17
21
#include < boost/geometry/algorithms/equals.hpp>
18
22
#include < boost/geometry/algorithms/transform.hpp>
19
23
#include < boost/geometry/algorithms/within.hpp>
@@ -32,44 +36,50 @@ template
32
36
typename TriangleStrategy,
33
37
typename SideStrategy // Actually, we need a triangle area strategy here.
34
38
>
35
- struct uniform_convex_fan
39
+ struct uniform_convex_polygon_sampler
36
40
{
37
41
private:
38
42
std::vector<double > accumulated_areas;
39
43
// It is hard to see a reason not to use double here. If a triangles
40
44
// relative size is smaller than doubles epsilon, it is too unlikely to
41
45
// realistically occur in a random sample anyway.
42
46
public:
43
- uniform_convex_fan (DomainGeometry const & g )
47
+ uniform_convex_polygon_sampler (DomainGeometry const & d )
44
48
{
45
49
accumulated_areas.push_back (0 );
46
- for (int i = 2 ; i < g. size () ; ++i) {
50
+ for (std:: size_t i = 2 ; i < boost:: size (d ) ; ++i) {
47
51
accumulated_areas.push_back (
48
52
accumulated_areas.back () +
49
53
std::abs (SideStrategy::template side_value<double , double >(
50
- *g .begin (),
51
- *(g .begin () + i - 1 ),
52
- *(g .begin () + i))));
54
+ *d .begin (),
55
+ *(d .begin () + i - 1 ),
56
+ *(d .begin () + i))));
53
57
}
54
58
}
55
59
bool equals (DomainGeometry const & l_domain,
56
60
DomainGeometry const & r_domain,
57
- uniform_convex_fan const & r_strategy) const
61
+ uniform_convex_polygon_sampler const & r_strategy) const
58
62
{
59
- if ( l_domain.size () != r_domain.size () ) return false ;
60
- for (int i = 0 ; i < l_domain.size (); ++i) {
63
+ if ( boost::size (l_domain) != boost::size (r_domain) )
64
+ {
65
+ return false ;
66
+ }
67
+ for (std::size_t i = 0 ; i < boost::size (l_domain); ++i)
68
+ {
61
69
if ( !boost::geometry::equals (*(l_domain.begin () + i),
62
70
*(r_domain.begin () + i)))
71
+ {
63
72
return false ;
73
+ }
64
74
}
65
75
return true ;
66
76
}
67
- template <typename Gen >
68
- Point apply (Gen & g, DomainGeometry const & d)
77
+ template <typename Generator >
78
+ Point apply (Generator & g, DomainGeometry const & d)
69
79
{
70
80
std::uniform_real_distribution<double > dist (0 , 1 );
71
- double r = dist (g) * accumulated_areas.back (),
72
- s = dist (g);
81
+ double r = dist (g) * accumulated_areas.back ();
82
+ double s = dist (g);
73
83
std::size_t i = std::distance (
74
84
accumulated_areas.begin (),
75
85
std::lower_bound (accumulated_areas.begin (),
@@ -92,4 +102,4 @@ struct uniform_convex_fan
92
102
93
103
}} // namespace boost::geometry
94
104
95
- #endif // BOOST_GEOMETRY_EXTENSIONS_RANDOM_STRATEGIES_AGNOSTIC_UNIFORM_CONVEX_FAN_HPP
105
+ #endif // BOOST_GEOMETRY_EXTENSIONS_RANDOM_STRATEGIES_AGNOSTIC_UNIFORM_CONVEX_POLYGON_SAMPLER_HPP
0 commit comments