Esempio n. 1
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--;
    }
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
Lines
Polygon::lines() const
{
    Lines lines;
    lines.reserve(this->points.size());
    for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) {
        lines.push_back(Line(*it, *(it + 1)));
    }
    lines.push_back(Line(this->points.back(), this->points.front()));
    return lines;
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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);
}
Esempio n. 8
0
Lines NewlineFilter::FlushLinesFromTerminatedProcess(DWORD pid, HANDLE handle)
{
    Lines lines;
    if (m_lineBuffers.find(pid) != m_lineBuffers.end())
    {
        if (!m_lineBuffers[pid].empty())
        {
            // timestamp not filled, this will be done by the loopback source
            lines.push_back(Line(0, FILETIME(), pid, "<flush>", m_lineBuffers[pid], nullptr));
        }
        m_lineBuffers.erase(pid);
    }
    auto processName = Str(ProcessInfo::GetProcessName(handle)).str();
    auto info = ProcessInfo::GetProcessInfo(handle);
    std::string infoStr = stringbuilder() << "<process started at " << info << " has now terminated>";
    lines.push_back(Line(0, FILETIME(), pid, processName, infoStr, nullptr));
    return lines;
}
Esempio n. 9
0
inline Lines to_lines(const ExPolygons &src) 
{
    size_t n_lines = 0;
    for (ExPolygons::const_iterator it_expoly = src.begin(); it_expoly != src.end(); ++ it_expoly) {
        n_lines += it_expoly->contour.points.size();
        for (size_t i = 0; i < it_expoly->holes.size(); ++ i)
            n_lines += it_expoly->holes[i].points.size();
    }
    Lines lines;
    lines.reserve(n_lines);
    for (ExPolygons::const_iterator it_expoly = src.begin(); it_expoly != src.end(); ++ it_expoly) {
        for (size_t i = 0; i <= it_expoly->holes.size(); ++ i) {
            const Points &points = ((i == 0) ? it_expoly->contour : it_expoly->holes[i - 1]).points;
            for (Points::const_iterator it = points.begin(); it != points.end()-1; ++it)
                lines.push_back(Line(*it, *(it + 1)));
            lines.push_back(Line(points.back(), points.front()));
        }
    }
    return lines;
}
Esempio n. 10
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;
}
Esempio n. 11
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;
}
Esempio n. 12
0
Lines DBWinReader::ProcessLine(const Line& line)
{
	Lines lines;
	if (m_lineBuffers.find(line.pid) == m_lineBuffers.end())
	{
		std::string message;
		message.reserve(4000);
		m_lineBuffers[line.pid] = std::move(message);
	}
	std::string& message = m_lineBuffers[line.pid];

	Line outputLine = line;
	for (auto i = line.message.begin(); i != line.message.end(); i++)
	{
		if (*i == '\r')
			continue;

		if (*i == '\n')
		{
			outputLine.message = std::move(message);
			message.clear();
			lines.push_back(outputLine);
		}
		else
		{
			message.push_back(char(*i));
		}
	}

	if (message.empty())
	{
		m_lineBuffers.erase(line.pid);
	}
	else if (m_autoNewLine || message.size() > 8192)	// 8k line limit prevents stack overflow in handling code 
	{
		outputLine.message = std::move(message);
		message.clear();
		lines.push_back(outputLine);
	}
	return lines;
}
Esempio n. 13
0
Lines
Polyline::lines() const
{
    Lines lines;
    if (this->points.size() >= 2) {
        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;
}
Esempio n. 14
0
void GetIntersection(Triangle& t1,Triangle& t2,Lines& res,std::vector<LineConf>* lines_conf,float*perimeter)
{
	Line ll;
	LineConf cc;
	if(CrossTriangles(t1,t2,&ll,cc.v))
	{
		if(!vecs_near(ll.v[0],ll.v[1]))
		{
			res.push_back(ll);
			if(lines_conf)lines_conf->push_back(cc);
			if(perimeter)*perimeter += ll.v[0].length(ll.v[1]);
		}//else printf(" BL ");
	}
}
Esempio n. 15
0
Lines NewlineFilter::Process(const Line& line)
{
    Lines lines;
    auto& message = m_lineBuffers[line.pid];
    message.reserve(4000);

    Line outputLine = line;
    for (auto it = line.message.begin(); it != line.message.end(); ++it)
    {
        if (*it == '\r')
            continue;

        if (*it == '\n')
        {
            outputLine.message = message;
            message.clear();
            lines.push_back(outputLine);
        }
        else
        {
            message.push_back(*it);
        }
    }

    if (message.empty())
    {
        m_lineBuffers.erase(line.pid);
    }
    else if (outputLine.pLogSource->GetAutoNewLine() || message.size() > 8192)	// 8k line limit prevents stack overflow in handling code
    {
        outputLine.message = message;
        message.clear();
        lines.push_back(outputLine);
    }
    return lines;
}
Esempio n. 16
0
Lines GetLine(CvPoints2d& cvline)
{
	Lines res;

	for (auto it = cvline.begin(); it != cvline.end(); ++it)
	{
		Line li;

		for (auto it2 = it->begin(); it2 != it->end(); ++it2)
		{
			li.push_back(Vector2(it2->x, it2->y));
		}

		res.push_back(li);
	}

	return res;
}
Esempio n. 17
0
bool FileHelper::open(const std::string file_name, Lines& lines)
{
    std::ifstream file(file_name.c_str(), std::ios::in);
    if (!file) 
    {
        return false;
    }

    lines.clear();
    char buffer[buffer_size];

    while (file.getline(buffer, buffer_size, '\n'))
    {
        lines.push_back(buffer);
    }
    
    return true;
}
Esempio n. 18
0
Lines
_clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons &clip,
    bool safety_offset_)
{
    // convert Lines to Polylines
    Polylines polylines;
    polylines.reserve(subject.size());
    for (Lines::const_iterator line = subject.begin(); line != subject.end(); ++line)
        polylines.push_back(*line);
    
    // perform operation
    polylines = _clipper_pl(clipType, polylines, clip, safety_offset_);
    
    // convert Polylines to Lines
    Lines retval;
    for (Polylines::const_iterator polyline = polylines.begin(); polyline != polylines.end(); ++polyline)
        retval.push_back(*polyline);
    return retval;
}
Esempio n. 19
0
//заносит результаты пересечений (отрезки) треугольников из g с плоскостью fl 
void FlatCrossGeometry(Geometry& g,flat fl,Lines& res,float*perimeter)
{
	Line ll;
	for(int b=0;b<g.boxes.size();b++)
		if(FlatCrossBox(Line(g.boxes[b].v[0],g.boxes[b].v[1]),fl))
			for(int i=0;i<g.boxes[b].boxes.size();i++)
			{
				int box_id = g.boxes[b].boxes[i];
				if(FlatCrossTriangle(g.tr[box_id],fl,&ll))
					if(!vecs_near(ll.v[0],ll.v[1]))
					{
						//для единообразной ориентации отрезков
						if(vec3::dot(fl.n,vec3::vect_mult(g.tr[box_id].norm,ll.v[0]-ll.v[1]))<0)swap(ll.v[0],ll.v[1]);
						
						res.push_back(ll);
						if(perimeter)*perimeter += ll.v[0].length(ll.v[1]);
					}//else printf(" BL ");
			}
}
Esempio n. 20
0
Lines DBWinReader::ProcessLines(const DBWinMessages& DBWinMessages)
{
	Lines resolvedLines = CheckHandleCache();
	for (auto i = DBWinMessages.begin(); i != DBWinMessages.end(); ++i)
	{
		std::string processName; 
		if (i->handle)
		{
			Handle processHandle(i->handle);
			processName = Str(ProcessInfo::GetProcessName(processHandle.get())).str();
			m_handleCache.Add(i->pid, std::move(processHandle));
		}

		auto lines = ProcessLine(Line(i->time, i->systemTime, i->pid, processName, i->message));
		for (auto line = lines.begin(); line != lines.end(); ++line)
			resolvedLines.push_back(*line);
	}

	return resolvedLines;
}
Esempio n. 21
0
Lines DBWinReader::CheckHandleCache()
{
	if ((m_timer.Get() - m_handleCacheTime) < HandleCacheTimeout)
		return Lines();

	Lines lines;
	Pids removedPids = m_handleCache.Cleanup();
	for (auto i = removedPids.begin(); i != removedPids.end(); i++)
	{
		DWORD pid = *i;
		if (m_lineBuffers.find(pid) != m_lineBuffers.end())
		{
			if (!m_lineBuffers[pid].empty())
				lines.push_back(Line(m_timer.Get(), GetSystemTimeAsFileTime(), pid, "<flush>", m_lineBuffers[pid]));
			m_lineBuffers.erase(pid);
		}
	}
	m_handleCacheTime = m_timer.Get();
	return lines;
}
Esempio n. 22
0
std::vector<Lines>
read_files(const std::vector<std::string>& fnames)
{
	if (fnames.empty())
		return std::move(std::vector<Lines>());
	std::vector<Lines> rs;
	for (auto fname : fnames)
	{
		Lines lines;
		std::ifstream ifile(fname);
		if (!ifile.is_open())
		{
			LOG(INFO) << _("Error opening extra file.")
			          << _(" Filename: ") << fname;
			return std::move(std::vector<Lines>());
		}
		for (std::string line; std::getline(ifile, line);)
			lines.push_back(line);
		rs.push_back(lines);
	}
	return rs;
}
Esempio n. 23
0
Line::operator Lines() const
{
    Lines lines;
    lines.push_back(*this);
    return lines;
}
Esempio n. 24
0
    virtual int run(int, char*[])
    {
        //
        // Terminate cleanly on receipt of a signal
        //
        shutdownOnInterrupt();

        //
        // Create an object adapter.
        //
        Ice::ObjectAdapterPtr adapter =
            communicator()->createObjectAdapterWithEndpoints("SimpleFilesystem", "default -h localhost -p 10000");

        //
        // Create the root directory (with name "/" and no parent)
        //
        DirectoryIPtr root = new DirectoryI(communicator(), "/", 0);
        root->activate(adapter);

        //
        // Create a file called "README" in the root directory
        //
        FileIPtr file = new FileI(communicator(), "README", root);
        Lines text;
        text.push_back("This file system contains a collection of poetry.");
        file->write(text);
        file->activate(adapter);

        //
        // Create a directory called "Coleridge" in the root directory
        //
        DirectoryIPtr coleridge = new DirectoryI(communicator(), "Coleridge", root);
        coleridge->activate(adapter);

        //
        // Create a file called "Kubla_Khan" in the Coleridge directory
        //
        file = new FileI(communicator(), "Kubla_Khan", coleridge);
        text.erase(text.begin(), text.end());
        text.push_back("In Xanadu did Kubla Khan");
        text.push_back("A stately pleasure-dome decree:");
        text.push_back("Where Alph, the sacred river, ran");
        text.push_back("Through caverns measureless to man");
        text.push_back("Down to a sunless sea.");
        file->write(text);
        file->activate(adapter);

        //
        // All objects are created, allow client requests now
        //
        adapter->activate();

        //
        // Wait until we are done
        //
        communicator()->waitForShutdown();
        if(interrupted())
        {
            cerr << appName() << ": received signal, shutting down" << endl;
        }

        return 0;
    }
Esempio n. 25
0
bool
BridgeDetector::detect_angle()
{
    if (this->_edges.empty() || this->_anchors.empty()) return false;

    /*  Outset the bridge expolygon by half the amount we used for detecting anchors;
        we'll use this one to clip our test lines and be sure that their endpoints
        are inside the anchors and not on their contours leading to false negatives. */
    Polygons clip_area;
    offset(this->expolygon, &clip_area, +this->extrusion_width/2);

    /*  we'll now try several directions using a rudimentary visibility check:
        bridge in several directions and then sum the length of lines having both
        endpoints within anchors */

    // we test angles according to configured resolution
    std::vector<double> angles;
    for (int i = 0; i <= PI/this->resolution; ++i)
        angles.push_back(i * this->resolution);

    // we also test angles of each bridge contour
    {
        Polygons pp = this->expolygon;
        for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
            Lines lines = p->lines();
            for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line)
                angles.push_back(line->direction());
        }
    }

    /*  we also test angles of each open supporting edge
        (this finds the optimal angle for C-shaped supports) */
    for (Polylines::const_iterator edge = this->_edges.begin(); edge != this->_edges.end(); ++edge) {
        if (edge->first_point().coincides_with(edge->last_point())) continue;
        angles.push_back(Line(edge->first_point(), edge->last_point()).direction());
    }

    // remove duplicates
    double min_resolution = PI/180.0;  // 1 degree
    std::sort(angles.begin(), angles.end());
    for (size_t i = 1; i < angles.size(); ++i) {
        if (xd::Geometry::directions_parallel(angles[i], angles[i-1], min_resolution)) {
            angles.erase(angles.begin() + i);
            --i;
        }
    }
    /*  compare first value with last one and remove the greatest one (PI)
        in case they are parallel (PI, 0) */
    if (xd::Geometry::directions_parallel(angles.front(), angles.back(), min_resolution))
        angles.pop_back();

    BridgeDirectionComparator bdcomp(this->extrusion_width);
    double line_increment = this->extrusion_width;
    bool have_coverage = false;
    for (std::vector<double>::const_iterator angle = angles.begin(); angle != angles.end(); ++angle) {
        Polygons my_clip_area = clip_area;
        ExPolygons my_anchors = this->_anchors;

        // rotate everything - the center point doesn't matter
        for (Polygons::iterator it = my_clip_area.begin(); it != my_clip_area.end(); ++it)
            it->rotate(-*angle, Point(0,0));
        for (ExPolygons::iterator it = my_anchors.begin(); it != my_anchors.end(); ++it)
            it->rotate(-*angle, Point(0,0));

        // generate lines in this direction
        BoundingBox bb;
        for (ExPolygons::const_iterator it = my_anchors.begin(); it != my_anchors.end(); ++it)
            bb.merge((Points)*it);

        Lines lines;
        for (coord_t y = bb.min.y; y <= bb.max.y; y += line_increment)
            lines.push_back(Line(Point(bb.min.x, y), Point(bb.max.x, y)));

        Lines clipped_lines;
        intersection(lines, my_clip_area, &clipped_lines);

        // remove any line not having both endpoints within anchors
        for (size_t i = 0; i < clipped_lines.size(); ++i) {
            Line &line = clipped_lines[i];
            if (!xd::Geometry::contains(my_anchors, line.a)
                    || !xd::Geometry::contains(my_anchors, line.b)) {
                clipped_lines.erase(clipped_lines.begin() + i);
                --i;
            }
        }

        std::vector<double> lengths;
        double total_length = 0;
        for (Lines::const_iterator line = clipped_lines.begin(); line != clipped_lines.end(); ++line) {
            double len = line->length();
            lengths.push_back(len);
            total_length += len;
        }
        if (total_length) have_coverage = true;

        // sum length of bridged lines
        bdcomp.dir_coverage[*angle] = total_length;

        /*  The following produces more correct results in some cases and more broken in others.
            TODO: investigate, as it looks more reliable than line clipping. */
        // $directions_coverage{$angle} = sum(map $_->area, @{$self->coverage($angle)}) // 0;

        // max length of bridged lines
        bdcomp.dir_avg_length[*angle] = !lengths.empty()
                                        ? *std::max_element(lengths.begin(), lengths.end())
                                        : 0;
    }

    // if no direction produced coverage, then there's no bridge direction
    if (!have_coverage) return false;

    // sort directions by score
    std::sort(angles.begin(), angles.end(), bdcomp);

    this->angle = angles.front();
    if (this->angle >= PI) this->angle -= PI;

//    #ifdef SLIC3R_DEBUG
//    printf("  Optimal infill angle is %d degrees\n", (int)Slic3r::Geometry::rad2deg(this->angle));
//    #endif

    return true;
}