make_square_polygon.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef BOOST_GEOMETRY_TEST_ROBUSTNESS_MAKE_SQUARE_POLYGON_HPP
  9. #define BOOST_GEOMETRY_TEST_ROBUSTNESS_MAKE_SQUARE_POLYGON_HPP
  10. #include <boost/geometry.hpp>
  11. template <typename Polygon, typename Generator, typename Settings>
  12. inline void make_square_polygon(Polygon& polygon, Generator& generator, Settings const& settings)
  13. {
  14. using namespace boost::geometry;
  15. typedef typename point_type<Polygon>::type point_type;
  16. typedef typename coordinate_type<Polygon>::type coordinate_type;
  17. coordinate_type x, y;
  18. x = generator();
  19. y = generator();
  20. typename ring_type<Polygon>::type& ring = exterior_ring(polygon);
  21. point_type p;
  22. set<0>(p, x); set<1>(p, y); append(ring, p);
  23. set<0>(p, x); set<1>(p, y + 1); append(ring, p);
  24. set<0>(p, x + 1); set<1>(p, y + 1); append(ring, p);
  25. set<0>(p, x + 1); set<1>(p, y); append(ring, p);
  26. set<0>(p, x); set<1>(p, y); append(ring, p);
  27. if (settings.triangular)
  28. {
  29. // Remove a point, generator says which
  30. int c = generator() % 4;
  31. if (c >= 1 && c <= 3)
  32. {
  33. ring.erase(ring.begin() + c);
  34. }
  35. }
  36. }
  37. #endif // BOOST_GEOMETRY_TEST_ROBUSTNESS_MAKE_SQUARE_POLYGON_HPP