Exemplo n.º 1
0
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;
    }
}
Exemplo n.º 2
0
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--;
    }
}
Exemplo n.º 3
0
void FileHelper::save(std::ostream& stream, Lines& lines)
{
    for (Lines::iterator i=lines.begin(); i != lines.end(); ++i)
    {
        stream << (*i).c_str() << std::endl;
    }
}
Exemplo n.º 4
0
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--;
				}
			}
		}
	}
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    Lines window;
    window.show();
    return app.exec();
}
Exemplo n.º 6
0
void
Parser::write(std::list<string>& args)
{
    DirectoryPrx dir = _dirs.front();
    string name = args.front();
    args.pop_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;
    for(std::list<string>::const_iterator i = args.begin(); i != args.end(); ++i)
    {
        l.push_back(*i);
    }
    f->write(l);
}
Exemplo n.º 7
0
int main ()
{
  using namespace Graph_lib;  // our graphics facilities are in Graph_lib namespace

  constexpr Point pt{100,100};    // to become top left corner of window

  Simple_window win {pt, 600, 400,"ch13.5_LineStile"};  // make a simple window, {top_left, width, hight, title}

  const int x_size = win.x_max();
  const int y_size = win.y_max();
  const int x_grid = 80;
  const int y_grid = 40;

  Lines grid;
  for (int x=x_grid; x<x_size; x+=x_grid)
    grid.add(Point{x,0},Point{x,y_size}); // vertical line
  for (int y=y_grid; y<y_size; y+=y_grid)
    grid.add(Point{0,y},Point{x_size,y});  // horizontal line

  grid.set_color(Color::red); // set color (chould affect both lines
  //grid.set_style(Line_style{Line_style::dot,2});
  //grid.set_style(Line_style::dashdot);
  grid.set_style(Line_style{Line_style::dashdot,2});

  win.attach(grid);

  win.wait_for_button();  // display!

}
Exemplo n.º 8
0
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;
            }
        }
    }
}
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
inline Lines to_lines(const Polygon &poly) 
{
    Lines lines;
    lines.reserve(poly.points.size());
    for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
        lines.push_back(Line(*it, *(it + 1)));
    lines.push_back(Line(poly.points.back(), poly.points.front()));
    return lines;
}
Exemplo n.º 11
0
void Starfield::draw() const {
    const RgbColor slowColor   = GetRGBTranslateColorShade(kStarColor, MEDIUM);
    const RgbColor mediumColor = GetRGBTranslateColorShade(kStarColor, LIGHT);
    const RgbColor fastColor   = GetRGBTranslateColorShade(kStarColor, LIGHTER);

    switch (g.ship.get() ? g.ship->presenceState : kNormalPresence) {
        default:
            if (!_warp_stars) {
                Points points;
                // we're not warping in any way
                for (const scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
                    if (star->speed != kNoStar) {
                        const RgbColor* color = &slowColor;
                        if (star->speed == kMediumStarSpeed) {
                            color = &mediumColor;
                        } else if (star->speed == kFastStarSpeed) {
                            color = &fastColor;
                        }

                        points.draw(star->location, *color);
                    }
                }
                break;
            }

        case kWarpInPresence:
        case kWarpOutPresence:
        case kWarpingPresence: {
            Lines lines;
            for (const scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
                if (star->speed != kNoStar) {
                    const RgbColor* color = &slowColor;
                    if (star->speed == kMediumStarSpeed) {
                        color = &mediumColor;
                    } else if (star->speed == kFastStarSpeed) {
                        color = &fastColor;
                    }

                    if (star->age > 1) {
                        lines.draw(star->location, star->oldLocation, *color);
                    }
                }
            }
            break;
        }
    }

    Points points;
    for (const scrollStarType* star : range(_stars + kSparkStarOffset, _stars + kAllStarNum)) {
        if ((star->speed != kNoStar) && (star->age > 0)) {
            const RgbColor color =
                    GetRGBTranslateColorShade(star->hue, (star->age >> kSparkAgeToShadeShift) + 1);
            points.draw(star->location, color);
        }
    }
}
Exemplo n.º 12
0
Lines
Polygon::lines() const
{
    Lines lines;
    for (int i = 0; i < this->points.size()-1; i++) {
        lines.push_back(Line(this->points[i], this->points[i+1]));
    }
    lines.push_back(Line(this->points.back(), this->points.front()));
    return lines;
}
Exemplo n.º 13
0
Lines
Polyline::lines() const
{
    Lines lines;
    lines.reserve(this->points.size() - 1);
    for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) {
        lines.push_back(Line(*it, *(it + 1)));
    }
    return lines;
}
Exemplo n.º 14
0
Lines
ExPolygonCollection::lines() const
{
    Lines lines;
    for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
        Lines ex_lines = it->lines();
        lines.insert(lines.end(), ex_lines.begin(), ex_lines.end());
    }
    return lines;
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
Lines GetLines(const CEdges& edges)
{
	Lines res;

	for (CEdges::const_iterator it = edges.begin(); it != edges.end(); ++it)
	{
		res.push_back(it->GetLine());
	}

	return res;
}
Exemplo n.º 18
0
int main(){
	Simple_window win2(Point(100, 100), 600, 400, "lines: +");

	Lines x;

	x.add(Point(100, 100), Point(200, 100));	// 1つ目のライン: 水平
	x.add(Point(150, 50), Point(150, 150));		// 2つ目のライン: 垂直

	win2.attach(x);
	win2.wait_for_button();		// 表示!
}
Exemplo n.º 19
0
Lines get_starts(TextIter Xi, TextIter Yi) {
    Lines lines;
    int C = Xi.compare(Yi);
    while (C < 0) {
        lines.push_back(Xi.get_offset());
        if (!Xi.forward_line())
            break;
        C = Xi.compare(Yi);
    }
    return lines;
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {

    QApplication app(argc, argv);

    Lines window;

    window.resize(280, 270);
    window.setWindowTitle("Lines");
    window.show();

    return app.exec();
}
Exemplo n.º 21
0
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);
    }
}
Exemplo n.º 22
0
void test_grid(Simple_window &win) {
    static const int x_size {win.x_max()}, y_size {win.y_max()};
    constexpr int x_grid {80}, y_grid {40};
    Lines grid;
    for (int x {x_grid}; x < x_size; x += x_grid)
        grid.add(Point{x, 0}, Point{x, y_size});
    for (int y {y_grid}; y < y_size; y += y_grid)
        grid.add(Point{0, y}, Point{x_size, y});
    grid.set_color(Color::yellow);
    grid.set_style(Line_style{Line_style::dash, 2});

    win.attach(grid);
    win.wait_for_button();
}
Exemplo n.º 23
0
void vavImage::ShowEdgeLine(const Lines& li)
{
	for (Lines::const_iterator it = li.begin(); it != li.end(); ++it)
	{
		int R = 255, B = 255, G = 255;
		for (Line::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
		{
			cv::Vec3b& intensity = m_Image.at<cv::Vec3b>(it2->y, it2->x);
			intensity[0] = R;
			intensity[1] = G;
			intensity[2] = B;
		}
	}
}
Exemplo n.º 24
0
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();
}
Exemplo n.º 25
0
bool
Polyline::is_straight() const
{
    /*  Check that each segment's direction is equal to the line connecting
        first point and last point. (Checking each line against the previous
        one would cause the error to accumulate.) */
    double dir = Line(this->first_point(), this->last_point()).direction();
    
    Lines lines = this->lines();
    for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
        if (!line->parallel_to(dir)) return false;
    }
    return true;
}
Exemplo n.º 26
0
inline Lines to_lines(const Polygons &polys) 
{
    size_t n_lines = 0;
    for (size_t i = 0; i < polys.size(); ++ i)
        n_lines += polys[i].points.size();
    Lines lines;
    lines.reserve(n_lines);
    for (size_t i = 0; i < polys.size(); ++ i) {
        const Polygon &poly = polys[i];
        for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
            lines.push_back(Line(*it, *(it + 1)));
        lines.push_back(Line(poly.points.back(), poly.points.front()));
    }
    return lines;
}
Exemplo n.º 27
0
inline Lines to_lines(const ExPolygon &src) 
{
    size_t n_lines = src.contour.points.size();
    for (size_t i = 0; i < src.holes.size(); ++ i)
        n_lines += src.holes[i].points.size();
    Lines lines;
    lines.reserve(n_lines);
    for (size_t i = 0; i <= src.holes.size(); ++ i) {
        const Polygon &poly = (i == 0) ? src.contour : src.holes[i - 1];
        for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
            lines.push_back(Line(*it, *(it + 1)));
        lines.push_back(Line(poly.points.back(), poly.points.front()));
    }
    return lines;
}
int main()
{
    Simple_window win {Point{100, 100}, 800, 1000, "Chapter 13 Drill"};

    Lines ls;
    for (int x = 100; x <= 800; x += 100)
        ls.add(Point{x, 0}, Point{x, 800});
    for (int y = 100; y <= 800; y += 100)
        ls.add(Point{0, y}, Point{800, y});

    string pic = "Instruments 1.jpg";
    string another_pic = "Instruments 2.jpg";

    Image im1 {Point{0, 0}, pic};
    im1.set_mask(Point{0, 0}, 200, 200);
    win.attach(im1);

    Image im2 {Point{200, 300}, pic};
    im2.set_mask(Point{0, 0}, 200, 200);
    win.attach(im2);

    Image im3 {Point{400, 600}, pic};
    im3.set_mask(Point{0, 0}, 200, 200);
    win.attach(im3);

    Vector_ref<Rectangle> rectangles;
    for (int i = 0; i < 8; ++i) {
        rectangles.push_back(new Rectangle{Point{100 * i, 100 * i}, 100, 100});
        rectangles[i].set_fill_color(Color::red);
        win.attach(rectangles[i]);
    }

    ls.set_color(Color::white);
    win.attach(ls);

    int row = 0;
    int col = 0;

    for (int i = 0; i < 100; ++i) {
        col = i % 8;
        if (i / 8 > row) ++row;
        Image im4 {Point{100 * row, 100 * col}, another_pic};
        im4.set_mask(Point{0, 0}, 100, 100);

        win.attach(im4);
        win.wait_for_button();
    }
}
Exemplo n.º 29
0
Point
Point::projection_onto(const MultiPoint &poly) const
{
    Point running_projection = poly.first_point();
    double running_min = this->distance_to(running_projection);
    
    Lines lines = poly.lines();
    for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
        Point point_temp = this->projection_onto(*line);
        if (this->distance_to(point_temp) < running_min) {
	        running_projection = point_temp;
	        running_min = this->distance_to(running_projection);
        }
    }
    return running_projection;
}
Exemplo n.º 30
0
void GetSection(Geometry*target,Geometry*section,Geometry*res,bool inside_section,bool back_faces,float*perimeter)
{
	Triangle cur_tr;
	Lines lines;
	std::vector<LineConf> lines_conf;


	for(int i=0;i<target->tr.size();i++){
		/*
	for(int b=0;b<target->boxes.size();b++)
		if(CrossBoxes(target->boxes[b].v[0],target->boxes[b].v[1],section->box1,section->box2))
			for(int bi=0;bi<target->boxes[b].boxes.size();bi++)
			{int i=target->boxes[b].boxes[bi];*/

		if(CrossBoxes(target->tr_bb[i].v[0],target->tr_bb[i].v[1],section->box1,section->box2))
	{
		cur_tr = target->tr[i];
		lines.clear();
		lines_conf.clear();
		GetCrTriangles(*section, cur_tr, lines,&lines_conf, target->tr_bb[i],perimeter);
		
		bool ins = section->Inside(cur_tr.v[0]);
		ins = xor(inside_section,ins);
		
		if(lines.size())
		{
			//static int cc=0;
			//cc++;

			CutTriangle(cur_tr,lines,lines_conf,ins,res,!back_faces);
			//if(cc==2)return;
		}else
		{
			if(ins)
			{
				if(back_faces){swap(cur_tr.v[0],cur_tr.v[1]);cur_tr.norm.Inv();}
				res->AddTriangle(cur_tr);
			}//else
		
		}

	}
	}
	//printf("\n\nSection's triangles:%d\n",res->tr.size());

}