16{
17#ifdef DEBUG_ARC_FITTING
18 static int irun = 0;
19 BoundingBox bbox_svg;
21 Polyline temp = Polyline(points);
22 {
23 std::stringstream stri;
24 stri << "debug_arc_fitting_" << irun << ".svg";
25 SVG svg(stri.str(), bbox_svg);
26 svg.draw(points, "blue", 50000);
27 svg.draw(temp, "red", 1);
28 svg.Close();
29 }
30 ++ irun;
31#endif
32
33 result.clear();
34 result.reserve(points.size() / 2);
35 if (points.size() < 3) {
36 PathFittingData data;
37 data.start_point_index = 0;
38 data.end_point_index = points.size() - 1;
40 result.push_back(data);
41 return;
42 }
43
44 size_t front_index = 0;
45 size_t back_index = 0;
46 ArcSegment last_arc;
47 bool can_fit = false;
49 current_segment.reserve(points.size());
50 ArcSegment target_arc;
51 for (size_t i = 0; i < points.size(); i++) {
52
53 back_index = i;
54 current_segment.push_back(points[i]);
55 if (back_index - front_index < 2)
56 continue;
57
60 tolerance,
62 if (can_fit) {
63
64 last_arc = target_arc;
65 if (back_index == points.size() - 1) {
66 result.emplace_back(PathFittingData{ front_index,
67 back_index,
69 last_arc });
70 front_index = back_index;
71 }
72 } else {
73 if (back_index - front_index > 2) {
74
75
76 result.emplace_back(PathFittingData{ front_index,
77 back_index - 1,
79 last_arc });
80 } else {
81
85 result.back().end_point_index = front_index + 1;
86 }
87 front_index = back_index - 1;
88 current_segment.clear();
89 current_segment.push_back(points[front_index]);
90 current_segment.push_back(points[front_index + 1]);
91 }
92 }
93
94 if (front_index != back_index) {
98 result.back().end_point_index = back_index;
99 }
100 result.shrink_to_fit();
101}
#define DEFAULT_SCALED_MAX_RADIUS
Definition Circle.hpp:68
#define DEFAULT_ARC_LENGTH_PERCENT_TOLERANCE
Definition Circle.hpp:70
static bool try_create_arc(const Points &points, ArcSegment &target_arc, double approximate_length, double max_radius=DEFAULT_SCALED_MAX_RADIUS, double tolerance=DEFAULT_SCALED_RESOLUTION, double path_tolerance_percent=DEFAULT_ARC_LENGTH_PERCENT_TOLERANCE)
Definition Circle.cpp:280
double length(const Points &pts)
Definition MultiPoint.hpp:181
BoundingBox get_extents(const ExPolygonsWithIds &e)
Definition Emboss.cpp:1374
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73
@ Arc_move_cw
Definition ArcFitter.hpp:16
@ Arc_move_ccw
Definition ArcFitter.hpp:17
@ Linear_move
Definition ArcFitter.hpp:15
@ Arc_Dir_CCW
Definition Circle.hpp:63