~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/src/PolylineCollection.cpp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "PolylineCollection.hpp"
 
2
 
 
3
namespace Slic3r {
 
4
 
 
5
void
 
6
PolylineCollection::chained_path(PolylineCollection* retval, bool no_reverse) const
 
7
{
 
8
    if (this->polylines.empty()) return;
 
9
    this->chained_path_from(this->polylines.front().first_point(), retval, no_reverse);
 
10
}
 
11
 
 
12
void
 
13
PolylineCollection::chained_path_from(Point start_near, PolylineCollection* retval, bool no_reverse) const
 
14
{
 
15
    Polylines my_paths = this->polylines;
 
16
    
 
17
    Points endpoints;
 
18
    for (Polylines::const_iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
 
19
        endpoints.push_back(it->first_point());
 
20
        if (no_reverse) {
 
21
            endpoints.push_back(it->first_point());
 
22
        } else {
 
23
            endpoints.push_back(it->last_point());
 
24
        }
 
25
    }
 
26
    
 
27
    while (!my_paths.empty()) {
 
28
        // find nearest point
 
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();
 
33
        }
 
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();
 
38
    }
 
39
}
 
40
 
 
41
Point
 
42
PolylineCollection::leftmost_point() const
 
43
{
 
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;
 
49
    }
 
50
    return p;
 
51
}
 
52
 
 
53
#ifdef SLIC3RXS
 
54
REGISTER_CLASS(PolylineCollection, "Polyline::Collection");
 
55
#endif
 
56
 
 
57
}