1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2009-2020 Barend Gehrels, Amsterdam, the Netherlands.
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_GEOMETRY_STAR_COMB_HPP
11 #define BOOST_GEOMETRY_STAR_COMB_HPP
17 #include <boost/tuple/tuple.hpp>
18 #include <boost/math/constants/constants.hpp>
20 #include <test_overlay_p_q.hpp>
23 template <typename Polygon, typename AddFunctor>
24 inline void make_star(Polygon& polygon, AddFunctor functor,
25 int count, double factor1, double factor2,
28 double orientation = 1.0)
37 double a1 = factor1 * 0.5 * dx;
38 double b1 = factor1 * 0.5 * dy;
39 double a2 = factor2 * 0.5 * dx;
40 double b2 = factor2 * 0.5 * dy;
42 double delta = orientation * boost::math::constants::pi<double>() * 2.0 / (count - 1);
43 double angle = offset * delta;
46 for (int i = 0; i < count - 1; i++, angle += delta)
48 bool even = i % 2 == 0;
49 double x = cx + (even ? a1 : a2) * sin(angle);
50 double y = cy + (even ? b1 : b2) * cos(angle);
51 functor(polygon, x, y, i);
62 functor(polygon, x0, y0, count);
66 template <typename Vector>
67 void ccw_pushback(Vector& vector, double x, double y, int)
69 vector.push_back(boost::make_tuple(x, y));
72 template <typename Polygon, typename AddFunctor>
73 inline void make_comb(Polygon& polygon, AddFunctor functor,
76 bool clockwise = true)
82 typedef boost::tuple<double, double> tup;
83 typedef std::vector<tup> vector_type;
86 // Create in clockwise order
87 make_comb(vec, ccw_pushback<vector_type>, count, close, true);
90 // (For GCC 3.4 have it const)
91 vector_type const& v = vec;
92 for (vector_type::const_reverse_iterator
93 it = v.rbegin(); it != v.rend(); ++it)
95 functor(polygon, it->get<0>(), it->get<1>(), n++);
101 functor(polygon, 25.0, 0.0, n++);
102 functor(polygon, 0.0, 25.0, n++);
103 functor(polygon, 25.0, 50.0, n++);
105 // Function parameters
106 double diff = (25.0 / (count - 0.5)) / 2.0;
109 double b2 = 25.0 - diff * 2.0;
111 double x1 = 50.0, x2 = 25.0;
113 for (int i = 0; i < count - 1; i++)
115 functor(polygon, x1, (x1 + b1), n++); x1 -= diff;
116 functor(polygon, x1, (x1 + b1), n++); x1 -= diff;
117 functor(polygon, x2, (x2 + b2), n++); x2 -= diff;
118 functor(polygon, x2, (x2 + b2), n++); x2 -= diff;
120 functor(polygon, x1, (x1 + b1), n++);
124 functor(polygon, 25.0, 0.0, 4);
129 #endif // BOOST_GEOMETRY_STAR_COMB_HPP