File tree Expand file tree Collapse file tree 1 file changed +14
-24
lines changed
Expand file tree Collapse file tree 1 file changed +14
-24
lines changed Original file line number Diff line number Diff line change @@ -18,37 +18,27 @@ class TreeSupportBaseCircle
1818{
1919protected:
2020 inline static Polygon base_circle;
21- inline static bool circle_generated = false ;
21+ inline static std::once_flag flag ;
2222
2323public:
2424 inline static constexpr int64_t base_radius = 50 ;
2525
2626 static Polygon getBaseCircle ()
2727 {
28- if (circle_generated)
29- {
30- return base_circle;
31- }
32- else
33- {
34- std::mutex critical_sections;
35- std::lock_guard<std::mutex> critical_section_progress (critical_sections);
36- if (circle_generated)
28+ std::call_once (
29+ flag,
30+ [&]()
3731 {
38- return base_circle;
39- }
40-
41- constexpr auto support_tree_circle_resolution = 12 ; // The number of vertices in each circle.
42- Polygon circle;
43- for (const uint64_t i : ranges::views::iota (0 , support_tree_circle_resolution))
44- {
45- const AngleRadians angle = static_cast <double >(i) / support_tree_circle_resolution * TAU;
46- circle.emplace_back (static_cast <coord_t >(std::cos (angle) * base_radius), static_cast <coord_t >(std::sin (angle) * base_radius));
47- }
48- base_circle = Polygon (circle);
49- circle_generated = true ;
50- return base_circle;
51- }
32+ constexpr auto support_tree_circle_resolution = 12 ; // The number of vertices in each circle.
33+ Polygon circle;
34+ for (const uint64_t i : ranges::views::iota (0 , support_tree_circle_resolution))
35+ {
36+ const AngleRadians angle = static_cast <double >(i) / support_tree_circle_resolution * TAU;
37+ circle.emplace_back (static_cast <coord_t >(std::cos (angle) * base_radius), static_cast <coord_t >(std::sin (angle) * base_radius));
38+ }
39+ base_circle = Polygon (circle);
40+ });
41+ return base_circle;
5242 }
5343};
5444
You can’t perform that action at this time.
0 commit comments