Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PolylineCollection.cpp « libslic3r « src « xs - github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3077b0e1ee28ea4cfedb680b4da66137d8a437e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "PolylineCollection.hpp"

namespace Slic3r {

void
PolylineCollection::chained_path(PolylineCollection* retval, bool no_reverse) const
{
    if (this->polylines.empty()) return;
    this->chained_path_from(this->polylines.front().first_point(), retval, no_reverse);
}

void
PolylineCollection::chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse) const
{
    Polylines my_paths = this->polylines;
    
    Points endpoints;
    for (Polylines::const_iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
        endpoints.push_back(it->first_point());
        if (no_reverse) {
            endpoints.push_back(it->first_point());
        } else {
            endpoints.push_back(it->last_point());
        }
    }
    
    while (!my_paths.empty()) {
        // find nearest point
        int start_index = start_near.nearest_point_index(endpoints);
        int path_index = start_index/2;
        if (start_index % 2 && !no_reverse) {
            my_paths.at(path_index).reverse();
        }
        retval->polylines.push_back(my_paths.at(path_index));
        my_paths.erase(my_paths.begin() + path_index);
        endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
        start_near = retval->polylines.back().last_point();
    }
}

Point
PolylineCollection::leftmost_point() const
{
    if (this->polylines.empty()) CONFESS("leftmost_point() called on empty PolylineCollection");
    Point p = this->polylines.front().leftmost_point();
    for (Polylines::const_iterator it = this->polylines.begin() + 1; it != this->polylines.end(); ++it) {
        Point p2 = it->leftmost_point();
        if (p2.x < p.x) p = p2;
    }
    return p;
}

void
PolylineCollection::append(const Polylines &pp)
{
    this->polylines.insert(this->polylines.end(), pp.begin(), pp.end());
}

}