1
#include "PolylineCollection.hpp"
6
PolylineCollection::chained_path(PolylineCollection* retval, bool no_reverse) const
8
if (this->polylines.empty()) return;
9
this->chained_path_from(this->polylines.front().first_point(), retval, no_reverse);
13
PolylineCollection::chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse) const
15
Polylines my_paths = this->polylines;
18
for (Polylines::const_iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
19
endpoints.push_back(it->first_point());
21
endpoints.push_back(it->first_point());
23
endpoints.push_back(it->last_point());
27
while (!my_paths.empty()) {
29
int start_index = start_near.nearest_point_index(endpoints);
30
int path_index = start_index/2;
31
if (start_index % 2 && !no_reverse) {
32
my_paths.at(path_index).reverse();
34
retval->polylines.push_back(my_paths.at(path_index));
35
my_paths.erase(my_paths.begin() + path_index);
36
endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
37
start_near = retval->polylines.back().last_point();
42
PolylineCollection::leftmost_point() const
44
if (this->polylines.empty()) CONFESS("leftmost_point() called on empty PolylineCollection");
45
Point p = this->polylines.front().leftmost_point();
46
for (Polylines::const_iterator it = this->polylines.begin() + 1; it != this->polylines.end(); ++it) {
47
Point p2 = it->leftmost_point();
48
if (p2.x < p.x) p = p2;
54
REGISTER_CLASS(PolylineCollection, "Polyline::Collection");