void Polyline::split_at(const Point &point, Polyline* p1, Polyline* p2) const { if (this->points.empty()) return; // find the line to split at size_t line_idx = 0; Point p = this->first_point(); double min = point.distance_to(p); Lines lines = this->lines(); for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) { Point p_tmp = point.projection_onto(*line); if (point.distance_to(p_tmp) < min) { p = p_tmp; min = point.distance_to(p); line_idx = line - lines.begin(); } } // create first half p1->points.clear(); for (Lines::const_iterator line = lines.begin(); line != lines.begin() + line_idx + 1; ++line) { if (!line->a.coincides_with(p)) p1->points.push_back(line->a); } // we add point instead of p because they might differ because of numerical issues // and caller might want to rely on point belonging to result polylines p1->points.push_back(point); // create second half p2->points.clear(); p2->points.push_back(point); for (Lines::const_iterator line = lines.begin() + line_idx; line != lines.end(); ++line) { p2->points.push_back(line->b); } }
static void listRecursive(const DirectoryPrx& dir, int depth = 0) { string indent(++depth, '\t'); NodeSeq contents = dir->list(); for(NodeSeq::const_iterator i = contents.begin(); i != contents.end(); ++i) { DirectoryPrx dir = DirectoryPrx::checkedCast(*i); FilePrx file = FilePrx::uncheckedCast(*i); cout << indent << (*i)->name() << (dir ? " (directory):" : " (file):") << endl; if(dir) { listRecursive(dir, depth); } else { Lines text = file->read(); for(Lines::const_iterator j = text.begin(); j != text.end(); ++j) { cout << indent << "\t" << *j << endl; } } } }
void Parser::cat(const string& name) { DirectoryPrx dir = _dirs.front(); NodeDesc d; try { d = dir->find(name); } catch(const NoSuchName&) { cout << "`" << name << "': no such file" << endl; return; } if(d.type == DirType) { cout << "`" << name << "': not a file" << endl; return; } FilePrx f = FilePrx::uncheckedCast(d.proxy); Lines l = f->read(); for(Lines::const_iterator i = l.begin(); i != l.end(); ++i) { cout << *i << endl; } }
void Context::splitLines() { for (auto line = lines.begin(); line != lines.end(); ++line) { auto &text = line->text; auto p = text.find('\n'); if (p == text.npos) continue; size_t old_pos = 0; Lines ls; while (1) { ls.push_back(Line{text.substr(old_pos, p - old_pos), line->n_indents}); p++; old_pos = p; p = text.find('\n', p); if (p == text.npos) { ls.push_back(Line{ text.substr(old_pos), line->n_indents }); break; } } lines.insert(line, ls.begin(), ls.end()); line = lines.erase(line); line--; } }
void vavImage::GetFeatureEdge(Lines& lines) { return; for (Lines::iterator it = lines.begin(); it != lines.end(); ++it) { Line& li = *it; if (li.size() == 3) { li.erase(li.begin() + 1); } else if (li.size() > 3) { Vector2 lastmove = li[1] - li[0]; for (int i = 2; i < li.size() - 1; ++i) { Vector2 move = li[i + 1] - li[i]; if (move == lastmove) { li[i - 1].x = -999; } lastmove = move; } for (int i = 1; i < li.size(); ++i) { if (li[i].x == -999) { li.erase(li.begin() + i); i--; } } } } }
void FileHelper::save(std::ostream& stream, Lines& lines) { for (Lines::iterator i=lines.begin(); i != lines.end(); ++i) { stream << (*i).c_str() << std::endl; } }
BoundingBox::BoundingBox(const Lines &lines) { Points points; for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) { points.push_back(line->a); points.push_back(line->b); } *this = BoundingBox(points); }
double MultiPoint::length() const { Lines lines = this->lines(); double len = 0; for (Lines::iterator it = lines.begin(); it != lines.end(); ++it) { len += it->length(); } return len; }
std::string Wipe::wipe(GCode &gcodegen, bool toolchange) { std::string gcode; /* Reduce feedrate a bit; travel speed is often too high to move on existing material. Too fast = ripping of existing material; too slow = short wipe path, thus more blob. */ double wipe_speed = gcodegen.writer.config.travel_speed.value * 0.8; // get the retraction length double length = toolchange ? gcodegen.writer.extruder()->retract_length_toolchange() : gcodegen.writer.extruder()->retract_length(); if (length > 0) { /* Calculate how long we need to travel in order to consume the required amount of retraction. In other words, how far do we move in XY at wipe_speed for the time needed to consume retract_length at retract_speed? */ double wipe_dist = scale_(length / gcodegen.writer.extruder()->retract_speed() * wipe_speed); /* Take the stored wipe path and replace first point with the current actual position (they might be different, for example, in case of loop clipping). */ Polyline wipe_path; wipe_path.append(gcodegen.last_pos()); wipe_path.append( this->path.points.begin() + 1, this->path.points.end() ); wipe_path.clip_end(wipe_path.length() - wipe_dist); // subdivide the retraction in segments double retracted = 0; Lines lines = wipe_path.lines(); for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) { double segment_length = line->length(); /* Reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one due to rounding (TODO: test and/or better math for this) */ double dE = length * (segment_length / wipe_dist) * 0.95; gcode += gcodegen.writer.set_speed(wipe_speed*60); gcode += gcodegen.writer.extrude_to_xy( gcodegen.point_to_gcode(line->b), -dE, (std::string)"wipe and retract" + (gcodegen.enable_cooling_markers ? ";_WIPE" : "") ); retracted += dE; } gcodegen.writer.extruder()->retracted += retracted; // prevent wiping again on same path this->reset_path(); } return gcode; }
std::string ExtrusionPath::gcode(Extruder* extruder, double e, double F, double xofs, double yofs, std::string extrusion_axis, std::string gcode_line_suffix) const { dSP; std::stringstream stream; stream.setf(std::ios::fixed); double local_F = F; Lines lines = this->polyline.lines(); for (Lines::const_iterator line_it = lines.begin(); line_it != lines.end(); ++line_it) { const double line_length = line_it->length() * SCALING_FACTOR; // calculate extrusion length for this line double E = 0; if (e > 0) { extruder->extrude(e * line_length); E = extruder->E; } // compose G-code line Point point = line_it->b; const double x = point.x * SCALING_FACTOR + xofs; const double y = point.y * SCALING_FACTOR + yofs; stream.precision(3); stream << "G1 X" << x << " Y" << y; if (E != 0) { stream.precision(5); stream << " " << extrusion_axis << E; } if (local_F != 0) { stream.precision(3); stream << " F" << local_F; local_F = 0; } stream << gcode_line_suffix; stream << "\n"; } return stream.str(); }