Skip to content

Commit c899eb6

Browse files
committed
[extensions][random] Naming and formatting fixes. GSoC acknowledgement
1 parent f24d604 commit c899eb6

12 files changed

+111
-63
lines changed

extensions/example/random/random_example.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
@@ -36,7 +39,10 @@ int main()
3639

3740
std::default_random_engine generator(1);
3841
polygon poly;
39-
boost::geometry::read_wkt("POLYGON((16 21,17.1226 17.5451,20.7553 17.5451,17.8164 15.4098,18.9389 11.9549,16 14.0902,13.0611 11.9549,14.1836 15.4098,11.2447 17.5451,14.8774 17.5451,16 21))", poly);
42+
boost::geometry::read_wkt("POLYGON((16 21,17.1226 17.5451,20.7553 17.5451,"
43+
"17.8164 15.4098,18.9389 11.9549,16 14.0902,13.0611 11.9549,"
44+
"14.1836 15.4098,11.2447 17.5451,14.8774 17.5451,16 21))",
45+
poly);
4046
box b(point(0, 0), point(10, 10));
4147
segment s(point(11, 0), point(21, 10));
4248
multi_point mp;

extensions/test/random/random.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
55

6+
// Contributed and/or modified by Tinko Bartels,
7+
// as part of Google Summer of Code 2019 program.
8+
69
// Use, modification and distribution is subject to the Boost Software License,
710
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
811
// http://www.boost.org/LICENSE_1_0.txt)
@@ -73,7 +76,9 @@ void test_polygon()
7376
typedef bg::model::polygon<point2d_cart> polygon;
7477
polygon poly;
7578
bg::read_wkt(
76-
"POLYGON((16 21,17.1226 17.5451,20.7553 17.5451, 17.8164 15.4098,18.9389 11.9549,16 14.0902,13.0611 11.9549, 14.1836 15.4098,11.2447 17.5451,14.8774 17.5451,16 21))",
79+
"POLYGON((16 21,17.1226 17.5451,20.7553 17.5451, 17.8164 15.4098,"
80+
"18.9389 11.9549,16 14.0902,13.0611 11.9549, 14.1836 15.4098,"
81+
"11.2447 17.5451,14.8774 17.5451,16 21))",
7782
poly);
7883
bg::random::uniform_point_distribution<polygon> poly_dist(poly);
7984
bg::random::uniform_point_distribution<polygon> poly_dist2;

include/boost/geometry/extensions/random/strategies/agnostic/uniform_convex_hull_rejection.hpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
@@ -18,7 +21,7 @@
1821
#include <boost/geometry/geometries/polygon.hpp>
1922
#include <boost/geometry/algorithms/convex_hull.hpp>
2023

21-
#include <boost/geometry/extensions/random/strategies/agnostic/uniform_convex_fan.hpp>
24+
#include <boost/geometry/extensions/random/strategies/agnostic/uniform_convex_polygon_sampler.hpp>
2225

2326
namespace boost { namespace geometry
2427
{
@@ -40,21 +43,21 @@ struct uniform_convex_hull_rejection
4043
private:
4144
typedef typename point_type<DomainGeometry>::type domain_point_type;
4245
typedef boost::geometry::model::ring<domain_point_type> ring;
43-
ring hull;
44-
uniform_convex_fan<Point, ring, TriangleStrategy, SideStrategy>
46+
ring m_hull;
47+
uniform_convex_polygon_sampler<Point, ring, TriangleStrategy, SideStrategy>
4548
m_strategy;
4649
public:
47-
uniform_convex_hull_rejection(DomainGeometry const& g) : m_strategy(hull)
50+
uniform_convex_hull_rejection(DomainGeometry const& d) : m_strategy(m_hull)
4851
{
49-
boost::geometry::convex_hull(g, hull);
52+
boost::geometry::convex_hull(d, m_hull);
5053
m_strategy =
51-
uniform_convex_fan
54+
uniform_convex_polygon_sampler
5255
<
5356
Point,
5457
ring,
5558
TriangleStrategy,
5659
SideStrategy
57-
>(hull);
60+
>(m_hull);
5861
}
5962
bool equals(DomainGeometry const& l_domain,
6063
DomainGeometry const& r_domain,
@@ -63,12 +66,12 @@ struct uniform_convex_hull_rejection
6366
return boost::geometry::equals(l_domain, r_domain)
6467
&& m_strategy.equals(l_domain, r_domain, r_strategy.m_strategy);
6568
}
66-
template<typename Gen>
67-
Point apply(Gen& g, DomainGeometry const& d)
69+
template<typename Generator>
70+
Point apply(Generator& g, DomainGeometry const& d)
6871
{
6972
Point p;
7073
do{
71-
p = m_strategy.apply(g, hull);
74+
p = m_strategy.apply(g, m_hull);
7275
}while( !boost::geometry::within(p, d) );
7376
return p;
7477
}

include/boost/geometry/extensions/random/strategies/agnostic/uniform_convex_fan.hpp include/boost/geometry/extensions/random/strategies/agnostic/uniform_convex_polygon_sampler.hpp

+26-16
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
811

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
1114

1215
#include <random>
1316
#include <vector>
1417
#include <cstdlib>
1518
#include <cmath>
1619

20+
#include <boost/range/size.hpp>
1721
#include <boost/geometry/algorithms/equals.hpp>
1822
#include <boost/geometry/algorithms/transform.hpp>
1923
#include <boost/geometry/algorithms/within.hpp>
@@ -32,44 +36,50 @@ template
3236
typename TriangleStrategy,
3337
typename SideStrategy //Actually, we need a triangle area strategy here.
3438
>
35-
struct uniform_convex_fan
39+
struct uniform_convex_polygon_sampler
3640
{
3741
private:
3842
std::vector<double> accumulated_areas;
3943
// It is hard to see a reason not to use double here. If a triangles
4044
// relative size is smaller than doubles epsilon, it is too unlikely to
4145
// realistically occur in a random sample anyway.
4246
public:
43-
uniform_convex_fan(DomainGeometry const& g)
47+
uniform_convex_polygon_sampler(DomainGeometry const& d)
4448
{
4549
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) {
4751
accumulated_areas.push_back(
4852
accumulated_areas.back() +
4953
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))));
5357
}
5458
}
5559
bool equals(DomainGeometry const& l_domain,
5660
DomainGeometry const& r_domain,
57-
uniform_convex_fan const& r_strategy) const
61+
uniform_convex_polygon_sampler const& r_strategy) const
5862
{
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+
{
6169
if( !boost::geometry::equals(*(l_domain.begin() + i),
6270
*(r_domain.begin() + i)))
71+
{
6372
return false;
73+
}
6474
}
6575
return true;
6676
}
67-
template<typename Gen>
68-
Point apply(Gen& g, DomainGeometry const& d)
77+
template<typename Generator>
78+
Point apply(Generator& g, DomainGeometry const& d)
6979
{
7080
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);
7383
std::size_t i = std::distance(
7484
accumulated_areas.begin(),
7585
std::lower_bound(accumulated_areas.begin(),
@@ -92,4 +102,4 @@ struct uniform_convex_fan
92102

93103
}} // namespace boost::geometry
94104

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

include/boost/geometry/extensions/random/strategies/agnostic/uniform_envelope_rejection.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
@@ -44,23 +47,23 @@ struct uniform_envelope_rejection
4447
envelope_type m_env;
4548
BoxStrategy m_env_strat;
4649
public:
47-
uniform_envelope_rejection(DomainGeometry const& g) :
48-
m_env(return_envelope<envelope_type>(g)),
50+
uniform_envelope_rejection(DomainGeometry const& d) :
51+
m_env(return_envelope<envelope_type>(d)),
4952
m_env_strat(m_env) {}
5053
bool equals(DomainGeometry const& l_domain,
5154
DomainGeometry const& r_domain,
5255
uniform_envelope_rejection const& r_strategy) const
5356
{
5457
return boost::geometry::equals(l_domain, r_domain);
5558
}
56-
template<typename Gen>
57-
Point apply(Gen& g, DomainGeometry const& d)
59+
template<typename Generator>
60+
Point apply(Generator& g, DomainGeometry const& d)
5861
{
5962
typedef typename point_type<DomainGeometry>::type domain_point;
6063
domain_point p;
6164
do {
6265
p = m_env_strat.apply(g, m_env);
63-
}while( !::boost::geometry::within(p, d) );
66+
} while( !::boost::geometry::within(p, d) );
6467
Point r;
6568
boost::geometry::transform(p, r);
6669
return r;

include/boost/geometry/extensions/random/strategies/agnostic/uniform_linear.hpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
@@ -41,16 +44,16 @@ template
4144
>
4245
struct uniform_linear_single
4346
{
44-
uniform_linear_single(DomainGeometry const& g) {}
47+
uniform_linear_single(DomainGeometry const& d) {}
4548
bool equals(DomainGeometry const& l_domain,
4649
DomainGeometry const& r_domain,
4750
uniform_linear_single const& r_strategy) const
4851
{
4952
return boost::geometry::equals(l_domain, r_domain);
5053
}
5154

52-
template<typename Gen>
53-
Point apply(Gen& g, DomainGeometry const& d)
55+
template<typename Generator>
56+
Point apply(Generator& g, DomainGeometry const& d)
5457
{
5558
typedef typename select_most_precise
5659
<
@@ -85,12 +88,12 @@ class uniform_linear_multi
8588
std::vector<domain_point_type> point_cache;
8689
std::vector<length_type> accumulated_lengths;
8790
public:
88-
uniform_linear_multi(DomainGeometry const& g)
91+
uniform_linear_multi(DomainGeometry const& d)
8992
{
9093
std::size_t i = 0;
91-
point_cache.push_back(*segments_begin(g)->first);
94+
point_cache.push_back(*segments_begin(d)->first);
9295
accumulated_lengths.push_back(0);
93-
for (auto it = segments_begin(g) ; it != segments_end(g) ; ++it)
96+
for (auto it = segments_begin(d) ; it != segments_end(d) ; ++it)
9497
{
9598
accumulated_lengths.push_back(
9699
accumulated_lengths.back() + length(*it));
@@ -120,8 +123,8 @@ class uniform_linear_multi
120123
}
121124
return true;
122125
}
123-
template<typename Gen>
124-
Point apply(Gen& g, DomainGeometry const& d)
126+
template<typename Generator>
127+
Point apply(Generator& g, DomainGeometry const& d)
125128
{
126129
typedef typename select_most_precise
127130
<

include/boost/geometry/extensions/random/strategies/agnostic/uniform_point_distribution_discrete.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
@@ -29,16 +32,16 @@ template
2932
>
3033
struct single_point_distribution
3134
{
32-
single_point_distribution(DomainGeometry const& g) {}
35+
single_point_distribution(DomainGeometry const& d) {}
3336
template<typename Strategy>
3437
bool equals(DomainGeometry const& l_domain,
3538
DomainGeometry const& r_domain,
3639
Strategy const& r_strategy) const
3740
{
3841
return boost::geometry::equals(l_domain.domain(), r_domain.domain());
3942
}
40-
template<typename Gen>
41-
Point apply(Gen& g, DomainGeometry const& d)
43+
template<typename Generator>
44+
Point apply(Generator& g, DomainGeometry const& d)
4245
{
4346
Point r;
4447
boost::geometry::transform(d, r);
@@ -68,8 +71,8 @@ struct multi_point_distribution
6871
}
6972
return true;
7073
}
71-
template<typename Gen>
72-
Point apply(Gen& g, DomainGeometry const& d)
74+
template<typename Generator>
75+
Point apply(Generator& g, DomainGeometry const& d)
7376
{
7477
Point r;
7578
if(boost::size(d) == 0) return r;

include/boost/geometry/extensions/random/strategies/cartesian/uniform_point_distribution_box.hpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Copyright (c) 2019 Tinko Bartels, Berlin, Germany.
44

5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2019 program.
7+
58
// Use, modification and distribution is subject to the Boost Software License,
69
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
710
// http://www.boost.org/LICENSE_1_0.txt)
@@ -76,19 +79,19 @@ template
7679
>
7780
struct interval_product_distribution
7881
{
79-
interval_product_distribution(DomainGeometry const& g) {}
82+
interval_product_distribution(DomainGeometry const& d) {}
8083
bool equals(DomainGeometry const& l_domain,
8184
DomainGeometry const& r_domain,
8285
interval_product_distribution const& r_strategy) const
8386
{
8487
return boost::geometry::equals(l_domain.domain(), r_domain.domain());
8588
}
86-
template<typename Gen>
87-
Point apply(Gen& g, DomainGeometry const& d)
89+
template<typename Generator>
90+
Point apply(Generator& g, DomainGeometry const& d)
8891
{
8992
Point r;
9093
for_each_coordinate(r,
91-
detail::interval_sample<Point, DomainGeometry, Gen>(d, g));
94+
detail::interval_sample<Point, DomainGeometry, Generator>(d, g));
9295
return r;
9396
}
9497
void reset(DomainGeometry const&) {};

0 commit comments

Comments
 (0)