]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
20effc67 | 2 | // Robustness Test |
7c673cae | 3 | |
20effc67 | 4 | // Copyright (c) 2009-2020 Barend Gehrels, Amsterdam, the Netherlands. |
7c673cae FG |
5 | |
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) | |
9 | ||
10 | #ifndef BOOST_GEOMETRY_STAR_COMB_HPP | |
11 | #define BOOST_GEOMETRY_STAR_COMB_HPP | |
12 | ||
13 | #include <iostream> | |
14 | #include <string> | |
15 | #include <vector> | |
16 | ||
7c673cae FG |
17 | #include <boost/tuple/tuple.hpp> |
18 | #include <boost/math/constants/constants.hpp> | |
19 | ||
20 | #include <test_overlay_p_q.hpp> | |
21 | ||
22 | ||
23 | template <typename Polygon, typename AddFunctor> | |
24 | inline void make_star(Polygon& polygon, AddFunctor functor, | |
25 | int count, double factor1, double factor2, | |
26 | double offset = 0.0, | |
27 | bool close = true, | |
28 | double orientation = 1.0) | |
29 | { | |
30 | // Create star | |
31 | double cx = 25.0; | |
32 | double cy = 25.0; | |
33 | ||
34 | double dx = 50.0; | |
35 | double dy = 50.0; | |
36 | ||
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; | |
41 | ||
42 | double delta = orientation * boost::math::constants::pi<double>() * 2.0 / (count - 1); | |
43 | double angle = offset * delta; | |
44 | double x0, y0; | |
45 | bool first = true; | |
46 | for (int i = 0; i < count - 1; i++, angle += delta) | |
47 | { | |
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); | |
52 | if (first) | |
53 | { | |
54 | x0 = x; | |
55 | y0 = y; | |
56 | first = false; | |
57 | } | |
58 | ||
59 | } | |
60 | if (close) | |
61 | { | |
62 | functor(polygon, x0, y0, count); | |
63 | } | |
64 | } | |
65 | ||
66 | template <typename Vector> | |
67 | void ccw_pushback(Vector& vector, double x, double y, int) | |
68 | { | |
69 | vector.push_back(boost::make_tuple(x, y)); | |
70 | } | |
71 | ||
72 | template <typename Polygon, typename AddFunctor> | |
73 | inline void make_comb(Polygon& polygon, AddFunctor functor, | |
74 | int count, | |
75 | bool close = true, | |
76 | bool clockwise = true) | |
77 | { | |
78 | int n = 0; | |
79 | ||
80 | if (! clockwise) | |
81 | { | |
82 | typedef boost::tuple<double, double> tup; | |
83 | typedef std::vector<tup> vector_type; | |
84 | vector_type vec; | |
85 | ||
86 | // Create in clockwise order | |
87 | make_comb(vec, ccw_pushback<vector_type>, count, close, true); | |
88 | ||
89 | // Add in reverse | |
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) | |
94 | { | |
95 | functor(polygon, it->get<0>(), it->get<1>(), n++); | |
96 | } | |
97 | return; | |
98 | } | |
99 | ||
100 | // Create comb | |
101 | functor(polygon, 25.0, 0.0, n++); | |
102 | functor(polygon, 0.0, 25.0, n++); | |
103 | functor(polygon, 25.0, 50.0, n++); | |
104 | ||
105 | // Function parameters | |
106 | double diff = (25.0 / (count - 0.5)) / 2.0; | |
107 | ||
108 | double b1 = -25.0; | |
109 | double b2 = 25.0 - diff * 2.0; | |
110 | ||
111 | double x1 = 50.0, x2 = 25.0; | |
112 | ||
113 | for (int i = 0; i < count - 1; i++) | |
114 | { | |
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; | |
119 | } | |
120 | functor(polygon, x1, (x1 + b1), n++); | |
121 | ||
122 | if (close) | |
123 | { | |
124 | functor(polygon, 25.0, 0.0, 4); | |
125 | } | |
126 | } | |
127 | ||
128 | ||
129 | #endif // BOOST_GEOMETRY_STAR_COMB_HPP | |
130 |