• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Robustness Test
3 //
4 // Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_GEOMETRY_TEST_ROBUSTNESS_MAKE_SQUARE_POLYGON_HPP
10 #define BOOST_GEOMETRY_TEST_ROBUSTNESS_MAKE_SQUARE_POLYGON_HPP
11 
12 #include <boost/geometry.hpp>
13 
14 template <typename Polygon, typename Generator, typename Settings>
make_square_polygon(Polygon & polygon,Generator & generator,Settings const & settings)15 inline void make_square_polygon(Polygon& polygon, Generator& generator, Settings const& settings)
16 {
17     using namespace boost::geometry;
18 
19     typedef typename point_type<Polygon>::type point_type;
20     typedef typename coordinate_type<Polygon>::type coordinate_type;
21 
22     coordinate_type x, y;
23     x = generator();
24     y = generator();
25 
26     typename ring_type<Polygon>::type& ring = exterior_ring(polygon);
27 
28     point_type p;
29     set<0>(p, x); set<1>(p, y);         append(ring, p);
30     set<0>(p, x); set<1>(p, y + 1);     append(ring, p);
31     set<0>(p, x + 1); set<1>(p, y + 1); append(ring, p);
32     set<0>(p, x + 1); set<1>(p, y);     append(ring, p);
33     set<0>(p, x); set<1>(p, y);         append(ring, p);
34 
35     if (settings.triangular)
36     {
37         // Remove a point, generator says which
38         int c = generator() % 4;
39         if (c >= 1 && c <= 3)
40         {
41             ring.erase(ring.begin() + c);
42         }
43     }
44 }
45 
46 #endif // BOOST_GEOMETRY_TEST_ROBUSTNESS_MAKE_SQUARE_POLYGON_HPP
47