示例#1
0
/// Locate a span in the state.
/// \param s The span we are locating.
/// \return Those ItemTokens that the span comprises.
const ItemTokens State::locate_span(const Span& s) const {
	Span tmps(_frontier);
	assert(tmps.left() <= s.left());
	assert(tmps.right() >= s.right());

	ItemTokens is;
	ItemTokens::const_iterator i;
	for (i = _frontier.begin(); i != _frontier.end(); i++) {
		if ((*i)->span().left() == s.left())
			break;
		assert((*i)->span().left() < s.left());
	}
	assert((*i)->span().left() == s.left());

	for (; i != _frontier.end(); i++) {
		is.push_back(*i);
		if ((*i)->span().right() == s.right())
			break;
		assert((*i)->span().right() < s.right());
	}
	assert((*i)->span().right() == s.right());

	assert(!is.empty());
	return is;
}
示例#2
0
	int ArcArcIntof(const Span& arc0, const Span& arc1, Point& pLeft, Point& pRight) {
		// Intof 2 arcs
		int numInts = Intof(Circle(arc0.pc, arc0.radius), Circle(arc1.pc, arc1.radius), pLeft, pRight);

		if(numInts == 0) {
			pLeft = arc0.p1;
			pLeft.ok = false;
			return 0;
		}
		int nLeft  = arc0.OnSpan(pLeft) && arc1.OnSpan(pLeft);
		int nRight = (numInts == 2)?arc0.OnSpan(pRight) && arc1.OnSpan(pRight) : 0;
		if(nLeft == 0 && nRight) pLeft = pRight;
		return nLeft + nRight;
	}
示例#3
0
/// Locate the left and right iterators of a span in the state.
/// The left iterator points to the leftmost *inside* the span.
/// The right iterator points to the rightmost *inside* the span.
/// (For a span containing one item, left == right.)
/// \param s The span we are locating.
/// \return A pair of ItemToken iterators, left and right.
pair<ItemTokens::const_iterator, ItemTokens::const_iterator> State::span_iterators(const Span& s) const {
	Span tmps(_frontier);
	assert(tmps.left() <= s.left());
	assert(tmps.right() >= s.right());

	ItemTokens::const_iterator l, r;

	ItemTokens::const_iterator i;
	for (i = _frontier.begin(); i != _frontier.end(); i++) {
		if ((*i)->span().left() == s.left())
			break;
		assert((*i)->span().left() < s.left());
	}
	assert((*i)->span().left() == s.left());
	l = i;

	for (; i != _frontier.end(); i++) {
		if ((*i)->span().right() == s.right())
			break;
		assert((*i)->span().right() < s.right());
	}
	assert((*i)->span().right() == s.right());
	r = i;

	return make_pair(l, r);
}
示例#4
0
void testRuntimeSpan(Span sp)
{
    ASSERT_NOEXCEPT(std::as_bytes(sp));

    auto spBytes = std::as_bytes(sp);
    using SB = decltype(spBytes);
    ASSERT_SAME_TYPE(const std::byte, typename SB::element_type);

    if (sp.extent == std::dynamic_extent)
        assert(spBytes.extent == std::dynamic_extent);
    else
        assert(spBytes.extent == sizeof(typename Span::element_type) * sp.extent);

    assert((void *) spBytes.data() == (void *) sp.data());
    assert(spBytes.size() == sp.size_bytes());
}
示例#5
0
already_AddRefed<nsIDocument>
DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf, SupportedType aType,
                           ErrorResult& aRv)
{
  // The new stream holds a reference to the buffer
  nsCOMPtr<nsIInputStream> stream;
  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
                                      reinterpret_cast<const char *>(aBuf.Elements()),
                                      aBuf.Length(), NS_ASSIGNMENT_DEPEND);
  if (NS_FAILED(rv)) {
    aRv.Throw(rv);
    return nullptr;
  }

  return ParseFromStream(stream, VoidString(), aBuf.Length(), aType, aRv);
}
示例#6
0
文件: Area.cpp 项目: gorilux/libarea
void CArea::SpanIntersections(const Span& span, std::list<Point> &pts)const
{
	// this returns all the intersections of this area with the given span, ordered along the span

	// get all points where this area's curves intersect the span
	std::list<Point> pts2;
	for(std::list<CCurve>::const_iterator It = m_curves.begin(); It != m_curves.end(); It++)
	{
		const CCurve &c = *It;
		c.SpanIntersections(span, pts2);
	}

	// order them along the span
	std::multimap<double, Point> ordered_points;
	for(std::list<Point>::iterator It = pts2.begin(); It != pts2.end(); It++)
	{
		Point &p = *It;
		double t;
		if(span.On(p, &t))
		{
			ordered_points.insert(std::make_pair(t, p));
		}
	}

	// add them to the given list of points
	for(std::multimap<double, Point>::iterator It = ordered_points.begin(); It != ordered_points.end(); It++)
	{
		Point p = It->second;
		pts.push_back(p);
	}
}
示例#7
0
int main()
{
    std::srand(time(0));
    Span sp = Span(10000);
    try
    {
        while (1)
            sp.addNumber(rand());
    }
    catch(std::exception &e)
    {
        std::cout	<< e.what() << std::endl;
    }
    std::cout << sp.shortestSpan() << std::endl;
    std::cout << sp.longestSpan() << std::endl;
}
示例#8
0
void testRuntimeSpan(Span sp)
{
    LIBCPP_ASSERT((noexcept(sp.template first<Count>())));
    LIBCPP_ASSERT((noexcept(sp.first(Count))));
    auto s1 = sp.template first<Count>();
    auto s2 = sp.first(Count);
    using S1 = decltype(s1);
    using S2 = decltype(s2);
    ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type);
    ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type);
    static_assert(S1::extent == Count, "");
    static_assert(S2::extent == std::dynamic_extent, "");
    assert(s1.data() == s2.data());
    assert(s1.size() == s2.size());
    assert(std::equal(s1.begin(), s1.end(), sp.begin()));
}
示例#9
0
Point Span::NearestPointToSpan(const Span& p, double &d)const
{
	Point midpoint = MidParam(0.5);
	Point np = p.NearestPoint(m_p);
	Point best_point = m_p;
	double dist = np.dist(m_p);
	if(p.m_start_span)dist -= (CArea::m_accuracy * 2); // give start of curve most priority
	Point npm = p.NearestPoint(midpoint);
	double dm = npm.dist(midpoint) - CArea::m_accuracy; // lie about midpoint distance to give midpoints priority
	if(dm < dist){dist = dm; best_point = midpoint;}
	Point np2 = p.NearestPoint(m_v.m_p);
	double dp2 = np2.dist(m_v.m_p);
	if(dp2 < dist){dist = dp2; best_point = m_v.m_p;}
	d = dist;
	return best_point;
}
示例#10
0
	static bool DoesIntersInterfere(const Point& pInt, const Kurve& k, double offset)  {
		// check that intersections don't interfere with the original kurve 
		Span sp;
		Point dummy;
		int kCheckVertex = 0;
		k.Get(kCheckVertex++, sp.p0, sp.pc);

		offset = fabs(offset) - geoff_geometry::TOLERANCE;
		while(kCheckVertex <= k.nSpans()) {
			sp.dir = k.Get(kCheckVertex++, sp.p1, sp.pc);
			sp.SetProperties(true);
			// check for interference 
			if(Dist(sp, pInt, dummy) < offset) return true;
			sp.p0 = sp.p1;
		}
		return false;	// intersection is ok
	}
示例#11
0
constexpr bool testConstexprSpan(Span sp)
{
    LIBCPP_ASSERT((noexcept(sp.template subspan<Offset>())));
    LIBCPP_ASSERT((noexcept(sp.subspan(Offset))));
    auto s1 = sp.template subspan<Offset>();
    auto s2 = sp.subspan(Offset);
    using S1 = decltype(s1);
    using S2 = decltype(s2);
    ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type);
    ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type);
    static_assert(S1::extent == (Span::extent == std::dynamic_extent ? std::dynamic_extent : Span::extent - Offset), "");
    static_assert(S2::extent == std::dynamic_extent, "");
    return
        s1.data() == s2.data()
     && s1.size() == s2.size()
     && std::equal(s1.begin(), s1.end(), sp.begin() + Offset, sp.end());
}
示例#12
0
int main()
{
	Span sp = Span(5);
	Span sp1 = Span(10000);
	Span sp2 = Span(10000);
	Span sp3 = Span(10);
	Span sp4 = Span(1);

	srand(time(NULL));
	sp.addNumber(5);
	sp.addNumber(3);
	sp.addNumber(17);
	sp.addNumber(9);
	sp.addNumber(11);
	std::cout << sp.shortestSpan() << std::endl;
	std::cout << sp.longestSpan() << std::endl;

	sp1.RandInterval(9000);
	std::cout << sp1.shortestSpan() << std::endl;
	std::cout << sp1.longestSpan() << std::endl;

	sp2.Interval(42, 9000);
	std::cout << sp2.shortestSpan() << std::endl;
	std::cout << sp2.longestSpan() << std::endl;

	sp3.RandInterval(9000);
	std::cout << sp3.shortestSpan() << std::endl;
	std::cout << sp3.longestSpan() << std::endl;

	sp4.addNumber(5);
	sp4.addNumber(6);
	std::cout << sp4.shortestSpan() << std::endl;
	std::cout << sp4.longestSpan() << std::endl;
	return (0);
}
示例#13
0
文件: main.cpp 项目: Strade288/42
int main()
{
	srand(std::time(0));
	try
	{
		Span sp = Span(5);
		sp.addNumber(5);
		sp.addNumber(3);
		sp.addNumber(17);
		sp.addNumber(9);
		sp.addNumber(11);
		std::cout << sp.shortestSpan() << std::endl;
		std::cout << sp.longestSpan() << std::endl;

		Span big(10000);
		big.initAll(randNumber);
		std::cout << big.shortestSpan() << std::endl;
		std::cout << big.longestSpan() << std::endl;

		Span sp2(1);
		std::cout << sp2.shortestSpan() << std::endl;
	}
	catch (std::exception & e)
	{
		std::cout << e.what() << std::endl;
	}
}
示例#14
0
void URI::set_uri(
    uri_identifier_code_t id,
    const Span<const uint8_t> &uri_field
)
{
    delete[] _uri;

    if (uri_field.empty()) {
        _uri = NULL;
        _uri_size = 0;
        return;
    }

    _uri = new uint8_t[uri_id_code_size + uri_field.size()];
    _uri_size = uri_id_code_size + uri_field.size();
    _uri[uri_id_index] = id;
    memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size());
}
示例#15
0
static void parseVar (Lexer& lex, SigPtr sig)
{
	std::string name;
	TyPtr ty;
	Span sp;

	parseVar(lex, name, ty, sp);

	for (auto& a : sig->args)
		if (a.first == name)
		{
			std::ostringstream ss;
			ss << "variable '" << name << "' already declared in signature";
			throw sp.die(ss.str());
		}

	sig->args.push_back(Sig::Arg { name, ty });
	sig->span = sig->span + sp;
}
示例#16
0
文件: main.cpp 项目: rapatel/SoftRast
void TriRasterizer::drawSpansBetweenEdges(const Edge &longEdge, const Edge &shortEdge)
{
    if(shortEdge.m_V1.m_Y == shortEdge.m_V2.m_Y) return; // horizontal edge, return

    // snap current y-axis val to next pixel center
    // using short edge as the reference top
    float currY = getNextPixCenter(shortEdge.m_V1.m_Y);
    float topY  = shortEdge.m_V2.m_Y;

    // get current colors
    Color currLongColor;
    Color currShortColor;

    // get inverse slopes
    float shortInvSlope = (shortEdge.m_V2.m_X == shortEdge.m_V1.m_X) ? 0.f :
        (shortEdge.m_V2.m_X-shortEdge.m_V1.m_X)/(shortEdge.m_V2.m_Y-shortEdge.m_V1.m_Y);
    float longInvSlope  = (longEdge.m_V2.m_X == longEdge.m_V1.m_X) ? 0.f :
        (longEdge.m_V2.m_X-longEdge.m_V1.m_X)/(longEdge.m_V2.m_Y-longEdge.m_V1.m_Y);

        // get current x-axis vals
    float currLongX  = longEdge.m_V1.m_X + (currY-longEdge.m_V1.m_Y) * longInvSlope;
    float currShortX = shortEdge.m_V1.m_X + (currY-shortEdge.m_V1.m_Y) * shortInvSlope;

    // move along edges
    Span span;
    while (currY < topY)
    {
        // TODO: only calc interpolatants once
        interpolateColor(currY, shortEdge.m_V1.m_Y, shortEdge.m_V2.m_Y,
            shortEdge.m_V1.m_Color, shortEdge.m_V2.m_Color, currShortColor);
        interpolateColor(currY, longEdge.m_V1.m_Y, longEdge.m_V2.m_Y,
            longEdge.m_V1.m_Color, longEdge.m_V2.m_Color, currLongColor);

        // set & draw span
        span.setSpan(currShortColor, currLongColor, currShortX, currLongX, currY);
        drawSpan(span);

        currY += 1.f;
        currShortX += shortInvSlope;
        currLongX += longInvSlope;
    }
}
示例#17
0
文件: span.cpp 项目: abners/brpc
Span* Span::CreateClientSpan(const std::string& full_method_name,
                             int64_t base_real_us) {
    Span* span = butil::get_object<Span>(Forbidden());
    if (__builtin_expect(span == NULL, 0)) {
        return NULL;
    }
    span->_log_id = 0;
    span->_base_cid = INVALID_BTHREAD_ID;
    span->_ending_cid = INVALID_BTHREAD_ID;
    span->_type = SPAN_TYPE_CLIENT;
    span->_async = false;
    span->_protocol = PROTOCOL_UNKNOWN;
    span->_error_code = 0;
    span->_request_size = 0;
    span->_response_size = 0;
    span->_base_real_us = base_real_us;
    span->_received_real_us = 0;
    span->_start_parse_real_us = 0;
    span->_start_callback_real_us = 0;
    span->_start_send_real_us = 0;
    span->_sent_real_us = 0;
    span->_next_client = NULL;
    span->_tls_next = NULL;
    span->_full_method_name = full_method_name;
    span->_info.clear();
    Span* parent = (Span*)bthread::tls_bls.rpcz_parent_span;
    if (parent) {
        span->_trace_id = parent->trace_id();
        span->_parent_span_id = parent->span_id();
        span->_local_parent = parent;
        span->_next_client = parent->_next_client;
        parent->_next_client = span;
    } else {
        span->_trace_id = GenerateTraceId();
        span->_parent_span_id = 0;
        span->_local_parent = NULL;
    }
    span->_span_id = GenerateSpanId();
    return span;
}
示例#18
0
	double Dist(const Span& sp, const Point& p , Point& pnear ) {
		// returns distance of p from span, pnear is the nearpoint on the span (or endpoint)
		if(!sp.dir) {
			double d, t;
			Point3d unused_pnear;
			d = Dist(Line(sp), Point3d(p), unused_pnear, t);
			if(t < -geoff_geometry::TOLERANCE) {
				pnear = sp.p0;						// nearpoint
				d = pnear.Dist(p);
			}
			else if(t > sp.length + geoff_geometry::TOLERANCE) {
				pnear = sp.p1;
				d = pnear.Dist(p);
			}
			return d;
		}
		else {
			// put pnear on the circle
			double radiusp;
			Vector2d v(sp.pc, p);
			if((radiusp = v.magnitude()) < geoff_geometry::TOLERANCE)	{
				// point specified on circle centre - use first point as near point
				pnear = sp.p0;						// nearpoint
				return sp.radius;
			}
			else	{
				pnear = v * (sp.radius / radiusp) + sp.pc;

				// check if projected point is on the arc
				if(sp.OnSpan(pnear)) return fabs(radiusp - sp.radius);
				// double      h1 = pnear.x - sp.p0.x ;
				// double      v1 = pnear.y - sp.p0.y ;
				// double      h2 = sp.p1.x - pnear.x ;
				// double      v2 = sp.p1.y - pnear.y ;
				//       if ( sp.dir * ( h1 * v2 - h2 * v1 ) >= 0 )return fabs(radiusp - sp.radius);

				// point not on arc so calc nearest end-point
				double ndist = p.Dist(sp.p0);
				double dist = p.Dist(sp.p1);
				if(ndist >=  dist) {
					// sp.p1 is near point
					pnear = sp.p1;
					return dist;
				}

				// sp.p0 is near point
				pnear = sp.p0;						// nearpoint
				return ndist ;
			}
		}
	}
void AdaptiveWaterline::adaptive_sampling_run() {
    minx = surf->bb.minpt.x - 2*cutter->getRadius();
    maxx = surf->bb.maxpt.x + 2*cutter->getRadius();
    miny = surf->bb.minpt.y - 2*cutter->getRadius();
    maxy = surf->bb.maxpt.y + 2*cutter->getRadius();
    Line* line = new Line( Point(minx,miny,zh) , Point(maxx,maxy,zh) );
    Span* linespan = new LineSpan(*line);
    
    xfibers.clear();
    Point xstart_p1 = Point( minx, linespan->getPoint(0.0).y,  zh );
    Point xstart_p2 = Point( maxx, linespan->getPoint(0.0).y,  zh );
    Point xstop_p1 = Point( minx, linespan->getPoint(1.0).y,  zh );
    Point xstop_p2 = Point( maxx, linespan->getPoint(1.0).y,  zh );
    Fiber xstart_f = Fiber( xstart_p1, xstart_p2 ) ;
    Fiber xstop_f = Fiber( xstop_p1, xstop_p2 ); 
    subOp[0]->run(xstart_f);
    subOp[0]->run(xstop_f);
    xfibers.push_back(xstart_f);
    std::cout << " XFiber adaptive sample \n";
    xfiber_adaptive_sample( linespan, 0.0, 1.0, xstart_f, xstop_f);
    
    yfibers.clear();
    Point ystart_p1 = Point( linespan->getPoint(0.0).x, miny,  zh );
    Point ystart_p2 = Point( linespan->getPoint(0.0).x, maxy,  zh );
    Point ystop_p1 = Point( linespan->getPoint(1.0).x, miny,  zh );
    Point ystop_p2 = Point( linespan->getPoint(1.0).x, maxy,  zh );
    Fiber ystart_f = Fiber( ystart_p1, ystart_p2 ) ;
    Fiber ystop_f = Fiber( ystop_p1, ystop_p2 ); 
    subOp[1]->run(ystart_f);
    subOp[1]->run(ystop_f);
    yfibers.push_back(ystart_f);
    std::cout << " YFiber adaptive sample \n";
    yfiber_adaptive_sample( linespan, 0.0, 1.0, ystart_f, ystop_f);
    
    delete line;
    delete linespan;
    
}
void DateTimeGrid::paintRowGrid( QPainter* painter,
                                  const QRectF& /*sceneRect*/,
                                  const QRectF& exposedRect,
                                  AbstractRowController* rowController,
                                  QWidget* /*widget*/ )
{
    if ( rowController && rowSeparators() ) {
        // First draw the rows
        QPen pen = painter->pen();
        pen.setBrush( QApplication::palette().dark() );
        pen.setStyle( Qt::DashLine );
        painter->setPen( pen );
        QModelIndex idx = rowController->indexAt( qRound( exposedRect.top() ) );
        qreal y = 0;
        while ( y < exposedRect.bottom() && idx.isValid() ) {
            const Span s = rowController->rowGeometry( idx );
            y = s.start()+s.length();
            //painter->drawLine( QPointF( sceneRect.left(), y ), QPointF( sceneRect.right(), y ) );
            // Is alternating background better?
            if ( idx.row()%2 ) painter->fillRect( QRectF( exposedRect.x(), s.start(), exposedRect.width(), s.length() ), QApplication::palette().alternateBase() );
            idx =  rowController->indexBelow( idx );
        }
    }
}
示例#21
0
Point Span::NearestPoint(const Span& p, double *d)const
{
	double best_dist;
	Point best_point = this->NearestPointToSpan(p, best_dist);

	// try the other way round too
	double best_dist2;
	Point best_point2 = p.NearestPointToSpan(*this, best_dist2);
	if(best_dist2 < best_dist)
	{
		best_point = NearestPoint(best_point2);
		best_dist = best_dist2;
	}

	if(d)*d = best_dist;
	return best_point;
}
示例#22
0
	bool	OnSpan(const Span& sp, const Point& p,  bool nearPoints, Point& pNear, Point& pOnSpan) {
		// function returns true if pNear == pOnSpan
		//			returns pNear & pOnSpan if nearPoints true
		//			pNear (nearest on unbound span)
		//			pOnSpan (nearest on finite span)
		if(sp.dir) {
			// arc
			if(fabs(p.Dist(sp.pc) - sp.radius) > geoff_geometry::TOLERANCE) {
				if(!nearPoints) return false;
			}

			pNear = On(Circle(sp.pc, sp.radius), p);

			if(sp.OnSpan(pNear)) {
				if(nearPoints) pOnSpan = pNear;
				return true; // near point is on arc - already calculated
			}

			// point not on arc return the nearest end-point
			if(nearPoints) pOnSpan = (p.Dist(sp.p0) >= p.Dist(sp.p1)) ?sp.p1 : sp.p0;
			return false;
		}
		else {
			// straight
			if(fabs(CLine(sp.p0, sp.vs).Dist(p)) > geoff_geometry::TOLERANCE) {
				if(!nearPoints) return false;
			}
			Vector2d v(sp.p0, p);
			double t = v * sp.vs;
			if(nearPoints) pNear = sp.vs * t + sp.p0;
			bool onSpan = (t > - geoff_geometry::TOLERANCE && t < sp.length + geoff_geometry::TOLERANCE);
			if(! onSpan) {
				if(nearPoints) pOnSpan = (p.Dist(sp.p0) >= p.Dist(sp.p1))?sp.p1 : sp.p0;
			}
			else {
				if(nearPoints) pOnSpan = pNear;
			}
			return onSpan;
		}
	}
示例#23
0
void Text::set_text(
    encoding_t text_encoding,
    const Span<const uint8_t> &language_code,
    const Span<const uint8_t> &text
)
{
    delete[] _text_record;

    _text_record_size = header_size + language_code.size() + text.size();
    _text_record = new uint8_t[_text_record_size];

    // build the header
    _text_record[header_index] = 0;
    if (text_encoding == UTF16) {
        _text_record[header_index] |= utf16_encoding_bit;
    }
    _text_record[header_index] |= language_code.size();

    // language code
    memcpy(_text_record + language_code_index, language_code.data(), language_code.size());

    // actual text
    memcpy(_text_record + language_code_index + language_code.size(), text.data(), text.size());
}
示例#24
0
文件: Access.cpp 项目: slaakko/cmajor
void CheckAccess(Cm::Sym::Symbol* fromSymbol, const Span& fromSpan, Cm::Sym::Symbol* toSymbol)
{
    if (!fromSymbol || !toSymbol) return;
    Cm::Sym::FunctionSymbol* toContainingFunction = toSymbol->ContainingFunction();
    if (toContainingFunction)
    {
        Cm::Sym::FunctionSymbol* fromFunction = fromSymbol->Function();
        if (fromFunction == toContainingFunction)
        {
            return;
        }
    }
    if (fromSymbol->IsFunctionSymbol())
    {
        Cm::Sym::FunctionSymbol* fromFun = static_cast<Cm::Sym::FunctionSymbol*>(fromSymbol);
        if (fromFun->IsFunctionTemplateSpecialization())
        {
            return;
        }
        if (fromFun->IsMemberOfTemplateType())
        {
            return;
        }
    }
    Cm::Sym::ClassTypeSymbol* toContainingClass = toSymbol->ContainingClass();
    if (toContainingClass)
    {
        CheckAccess(fromSymbol, fromSpan, toContainingClass);
    }
    switch (toSymbol->DeclaredAccess())
    {
        case Cm::Sym::SymbolAccess::public_:
        {
            return;
        }
        case Cm::Sym::SymbolAccess::protected_:
        {
            Cm::Sym::ClassTypeSymbol* fromContainingClass = fromSymbol->ContainingClass();
            if (fromContainingClass)
            {
                if (toContainingClass->IsSameParentOrAncestorOf(fromContainingClass))
                {
                    return;
                }
                if (fromContainingClass->HasBaseClass(toContainingClass))
                {
                    return;
                }
            }
            break;
        }
        case Cm::Sym::SymbolAccess::internal_:
        {
            return;
        }
        case Cm::Sym::SymbolAccess::private_:
        {
            if (toContainingClass)
            {
                Cm::Sym::ClassTypeSymbol* fromContainingClass = fromSymbol->ContainingClass();
                if (toContainingClass->IsSameParentOrAncestorOf(fromContainingClass))
                {
                    return;
                }
            }
            break;
        }
    }
    Span span = fromSpan.Valid() ? fromSpan : fromSymbol->GetSpan();
    throw Cm::Core::Exception(toSymbol->TypeString() + " '" + toSymbol->FullName() + "' is inaccessible due to its protection level", span, toSymbol->GetSpan());
}
示例#25
0
void PolygonClipping2D(
    const Span<glm::vec2> &  subject,
    const Span<glm::vec2> &  clipping,
    std::vector<glm::vec2> & result)
{
    Assert(subject.size() > 2);
    Assert(clipping.size() > 2);

    std::vector<glm::vec2> input;
    std::vector<glm::vec2> output;

    /**
     * Determine winding order of clipping polygon
     */
    bool clippingCCW = false;
    {
        auto edge0 = glm::vec2(
            clipping[1].x - clipping[0].x, clipping[1].y - clipping[0].y);
        auto edge1 = glm::vec2(
            clipping[2].x - clipping[1].x, clipping[2].y - clipping[1].y);
        auto sign = (edge0.x * edge1.y) - (edge0.y * edge1.x);
        clippingCCW = sign >= 0;
    }

    //    std::cout << "Clipping: ";
    //    for (auto & v : clipping.toVector()) {
    //        std::cout << v << "; ";
    //    }
    //    std::cout << std::endl;

    output = subject.toVector();

    for (int c0 = 0; c0 < clipping.size(); c0++)
    {
        auto c1 = (c0 + 1) % clipping.size();

        auto & C0 = clipping[c0];
        auto & C1 = clipping[c1];

        Ray2D edge =
            clippingCCW ? Ray2D::fromTo(C0, C1) : Ray2D::fromTo(C1, C0);
        //        std::cout << edge << " " << clippingCCW << ": ";
        //        for (auto & v : output) {
        //            std::cout << v << " ";
        //        }
        //        std::cout << " -> ";

        input = output;
        output.clear();

        auto S = input.back();

        for (int i = 0; i < input.size(); i++)
        {
            auto & E = input[i];

            if (PointRay2DHalfspace(E, edge) <= 0)
            {
                if (PointRay2DHalfspace(S, edge) > 0)
                {
                    bool exists;
                    output.push_back(Ray2DIntersectionPoint(
                        Ray2D::fromTo(S, E), edge, exists));
                    Assert(exists);
                }
                output.push_back(E);
            }
            else if (PointRay2DHalfspace(S, edge) <= 0)
            {
                bool exists;
                output.push_back(
                    Ray2DIntersectionPoint(Ray2D::fromTo(S, E), edge, exists));
                Assert(exists);
            }

            S = E;
        }

        //        for (auto & v : output) {
        //            std::cout << v << " ";
        //        }
        //        std::cout << std::endl;
    }

    /**
     * Populate result
     */
    result = output;
}
示例#26
0
 void set_payload(Span new_load)
 {
   pckt_->set_data_end(pckt_->ip_header_length() + header_size() + new_load.size());
   memcpy(payload().data(), new_load.data(), payload().size());
 }
}

KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, DateTimeGrid, "test" ) {
    QStandardItemModel model( 3, 2 );
    DateTimeGrid grid;
    QDateTime dt = QDateTime::currentDateTime();
    grid.setModel( &model );
    grid.setStartDateTime( dt.addDays( -10 ) );

    model.setData( model.index( 0, 0 ), dt,               StartTimeRole );
    model.setData( model.index( 0, 0 ), dt.addDays( 17 ), EndTimeRole );

    model.setData( model.index( 2, 0 ), dt.addDays( 18 ), StartTimeRole );
    model.setData( model.index( 2, 0 ), dt.addDays( 19 ), EndTimeRole );

    Span s = grid.mapToChart( model.index( 0, 0 ) );
    //qDebug() << "span="<<s;

    assertTrue( s.start()>0 );
    assertTrue( s.length()>0 );

    grid.mapFromChart( s, model.index( 1, 0 ) );

    QDateTime s1 = model.data( model.index( 0, 0 ), StartTimeRole ).toDateTime();
    QDateTime e1 = model.data( model.index( 0, 0 ), EndTimeRole ).toDateTime();
    QDateTime s2 = model.data( model.index( 1, 0 ), StartTimeRole ).toDateTime();
    QDateTime e2 = model.data( model.index( 1, 0 ), EndTimeRole ).toDateTime();

    assertTrue( s1.isValid() );
    assertTrue( e1.isValid() );
    assertTrue( s2.isValid() );
示例#28
0
	int Kurve::OffsetMethod1(Kurve& kOffset, double off, int direction,  int method, int& ret)const
	{
		// offset kurve with simple span elimination
		// direction 1 = left,  -1 = right

		// ret  = 0		- kurve offset ok
		//		= 1		- kurve has differential scale (not allowed)
		//		= 2		- offset failed
		//      = 3		- offset too large
		if(this == &kOffset) FAILURE(L"Illegal Call - 'this' must not be kOffset");
		double offset = (direction == GEOFF_LEFT)?off : -off;

		if(fabs(offset) < geoff_geometry::TOLERANCE || m_nVertices < 2) {
			kOffset = *this;
			ret = 0;
			return 1;
		}

		Span curSpan, curSpanOff;	// current & offset spans
		Span prevSpanOff;			// previous offset span
		Point p0, p1;				// Offset span intersections

		// offset Kurve
		kOffset = Matrix(*this);

		if(m_mirrored) offset = -offset;
		int RollDir = ( off < 0 ) ? direction : - direction;				// Roll arc direction

		double scalex;
		if(!GetScale(scalex)) {
			ret = 1;
			return 0;	// differential scale
		}
		offset /= scalex;

		bool bClosed = Closed();
		int nspans = nSpans();
		if(bClosed) {
			Get(nspans, curSpan, true);						// assign previus span for closed

			prevSpanOff = curSpan.Offset(offset);
			nspans++; // read first again
		}

		for(int spannumber = 1; spannumber <= nspans; spannumber++) {
			if(spannumber > nSpans())
				Get(1, curSpan, true);						// closed kurve - read first span again
			else
				Get(spannumber, curSpan, true);

			if(!curSpan.NullSpan) {
				int numint = 0;
				curSpanOff = curSpan.Offset(offset);
				curSpanOff.ID = 0;
				if(!kOffset.m_started) {
					kOffset.Start(curSpanOff.p0);
					kOffset.AddSpanID(0);
				}

				if(spannumber > 1) {
					// see if tangent
					double d = curSpanOff.p0.Dist(prevSpanOff.p1);
					if((d > geoff_geometry::TOLERANCE) && (curSpanOff.NullSpan == false && prevSpanOff.NullSpan == false)) {
						// see if offset spans intersect

						double cp = prevSpanOff.ve ^ curSpanOff.vs;
						bool inters = (cp > 0 && direction == GEOFF_LEFT) || (cp < 0 && direction == GEOFF_RIGHT);

						if(inters) {
							double t[4];
							numint = prevSpanOff.Intof(curSpanOff, p0, p1, t);
						}

						if(numint == 1) {
							// intersection - modify previous endpoint
							kOffset.Replace(kOffset.m_nVertices-1, prevSpanOff.dir, p0, prevSpanOff.pc, prevSpanOff.ID);
						}
						else {
							// 0 or 2 intersections, add roll around (remove -ve loops in elimination function)
							if(kOffset.Add(RollDir, curSpanOff.p0, curSpan.p0, false))	kOffset.AddSpanID(ROLL_AROUND);
						}
					}
				}

				// add span
				if(spannumber < m_nVertices) {
					curSpanOff.ID = spannumber;
					kOffset.Add(curSpanOff, false);
				}
				else if(numint == 1)		// or replace the closed first span
					kOffset.Replace(0, 0, p0, Point(0, 0), 0);

			}
			if(!curSpanOff.NullSpan)prevSpanOff = curSpanOff;
		}		// end of main pre-offsetting loop


#ifdef _DEBUG
//testDraw->AddKurve("", &kOffset, 0, GREEN);
//		outXML oxml(L"c:\\temp\\eliminateLoops.xml");
//		oxml.startElement(L"eliminateLoops");
//		oxml.Write(kOffset, L"kOffset");
//		oxml.endElement();
#endif
		// eliminate loops
		if(method == NO_ELIMINATION) {
			ret = 0;
			return 1;
		}
		kOffset = eliminateLoops(kOffset, *this, offset, ret);

		if(ret == 0 && bClosed) {
			// check for inverted offsets of closed kurves
			if(kOffset.Closed()) {
				double a = Area();
				int dir = (a < 0);
				double ao = kOffset.Area();
				int dirOffset = ao < 0;

				if(dir != dirOffset)
					ret = 3;
				else {
					// check area change compatible with offset direction - catastrophic failure
					bool bigger = (a > 0 && offset > 0) || (a < 0 && offset < 0);
					if(bigger && fabs(ao) < fabs(a)) ret = 2;
				}
			}
			else
				ret = 2;			// started closed but now open??
		}
		return (ret == 0)?1 : 0;
	}
示例#29
0
	static Kurve eliminateLoops(const Kurve& k , const Kurve& originalk, double offset, int& ret) {
		// a simple loop elimination routine based on first offset ideas in Peps
		// this needs extensive work for future
		// start point musn't disappear & only one valid offset is determined
		//
		// ret = 0 for ok
		// ret = 2 for impossible geometry
		
		Span sp0, sp1;
		Point pInt, pIntOther;

		Kurve ko;											// eliminated output
		ko = Matrix(k);
		int kinVertex = 0;

		while(kinVertex <= k.nSpans()) {
			bool clipped = false ;                                       // not in a clipped section (assumption with this simple method)

			sp0.dir = k.Get(kinVertex, sp0.p0, sp0.pc);
			sp0.ID = k.GetSpanID(kinVertex++);
			if (kinVertex == 1)	{
				ko.Start(sp0.p0);							// start point mustn't dissappear for this simple method
				ko.AddSpanID(sp0.ID);
			}
			if (kinVertex <= k.nSpans()) {   // any more?
				int ksaveVertex = kinVertex ;
				sp0.dir = k.Get(kinVertex, sp0.p1, sp0.pc);	// first span
				sp0.ID = k.GetSpanID(kinVertex++);

				sp0.SetProperties(true);

				int ksaveVertex1 = kinVertex;									// mark position AA		
				if (kinVertex <= k.nSpans()) {	// get the next but one span			
					sp1.dir = k.Get(kinVertex, sp1.p0, sp1.pc);
					sp1.ID = k.GetSpanID(kinVertex++);
					int ksaveVertex2 = kinVertex;								// mark position BB

					int fwdCount = 0;
					while(kinVertex <= k.nSpans()) {					
						sp1.dir = k.Get(kinVertex, sp1.p1, sp1.pc);			// check span
						sp1.ID = k.GetSpanID(kinVertex++);
						sp1.SetProperties(true);
			
						double t[4];
						int numint = sp0.Intof(sp1, pInt, pIntOther, t);			// find span intersections
						if(numint && sp0.p0.Dist(pInt) < geoff_geometry::TOLERANCE ) numint=0;	// check that intersection is not at the start of the check span					
						if(numint ) {

							if(numint == 2) {
								// choose first intercept on sp0
								Span spd = sp0;
								spd.p1 = pInt;
								spd.SetProperties(true);
								double dd = spd.length;

								spd.p1 = pIntOther;
								spd.SetProperties(true);
								if(dd > spd.length) pInt = pIntOther;
								numint = 1;

							}
							ksaveVertex = ksaveVertex1 ;

							clipped = true ;			// in a clipped section		
							if(DoesIntersInterfere(pInt, originalk, offset) == false) {
								sp0.p1 = pInt;			// ok so truncate this span to the intersection
								clipped = false;		// end of clipped section
								break;
							}
							// no valid intersection found so carry on
						}
						sp1.p0 = sp1.p1 ;		// next
						ksaveVertex1 = ksaveVertex2 ;							// pos AA = BB
						ksaveVertex2 = kinVertex;								// mark 

						if((kinVertex > k.nSpans() || fwdCount++ > 25) && clipped == false) break;
					}
				}

				if(clipped) {
					ret = 2;	// still in a clipped section - error

					return ko;
				}

				ko.Add(sp0, false);

				kinVertex = ksaveVertex;
			}
		}
		ret = 0;

		return ko; // no more spans - seems ok
	}
示例#30
0
void AdaptiveWaterline::adaptive_sampling_run() {
    minx = surf->bb.minpt.x - 2*cutter->getRadius();
    maxx = surf->bb.maxpt.x + 2*cutter->getRadius();
    miny = surf->bb.minpt.y - 2*cutter->getRadius();
    maxy = surf->bb.maxpt.y + 2*cutter->getRadius();
    Line* line = new Line( Point(minx,miny,zh) , Point(maxx,maxy,zh) );
    Span* linespan = new LineSpan(*line);
    
#ifdef _WIN32 // OpenMP task not supported with the version 2 of VS2013 OpenMP
	#pragma omp parallel sections
	{
		#pragma omp section // Replace OMP Task by Parallel sections
		{ // first child
#else
#pragma omp parallel
	{
#pragma omp single nowait
		{ // initial root task
#pragma omp task
			{ // first child task
#endif // _WIN32
				xfibers.clear();
				Point xstart_p1 = Point(minx, linespan->getPoint(0.0).y, zh);
				Point xstart_p2 = Point(maxx, linespan->getPoint(0.0).y, zh);
				Point xstop_p1 = Point(minx, linespan->getPoint(1.0).y, zh);
				Point xstop_p2 = Point(maxx, linespan->getPoint(1.0).y, zh);
				Fiber xstart_f = Fiber(xstart_p1, xstart_p2);
				Fiber xstop_f = Fiber(xstop_p1, xstop_p2);
				subOp[0]->run(xstart_f);
				subOp[0]->run(xstop_f);
				xfibers.push_back(xstart_f);
				std::cout << " XFiber adaptive sample \n";
				xfiber_adaptive_sample(linespan, 0.0, 1.0, xstart_f, xstop_f);
#ifdef _WIN32 // OpenMP task not supported with the version 2 of VS2013 OpenMP
		}
		#pragma omp section
		{ // second child
#else
		}
# pragma omp task
			{ // second child task
#endif // _WIN32
				yfibers.clear();
				Point ystart_p1 = Point(linespan->getPoint(0.0).x, miny, zh);
				Point ystart_p2 = Point(linespan->getPoint(0.0).x, maxy, zh);
				Point ystop_p1 = Point(linespan->getPoint(1.0).x, miny, zh);
				Point ystop_p2 = Point(linespan->getPoint(1.0).x, maxy, zh);
				Fiber ystart_f = Fiber(ystart_p1, ystart_p2);
				Fiber ystop_f = Fiber(ystop_p1, ystop_p2);
				subOp[1]->run(ystart_f);
				subOp[1]->run(ystop_f);
				yfibers.push_back(ystart_f);
				std::cout << " YFiber adaptive sample \n";
				yfiber_adaptive_sample(linespan, 0.0, 1.0, ystart_f, ystop_f);
#ifdef _WIN32 // OpenMP task not supported with the version 2 of VS2013 OpenMP
		}
	} // end omp parallel
#else
            }
        }
    } // end omp parallel
#endif // _WIN32

    delete line;
    delete linespan;
    
}