int main () { try { saga::session s; saga::context c1; saga::context c0; c1.set_attribute ("testkey", "testval 1"); c0.set_attribute ("testkey", "testval 2"); saga::context c2 (c1); saga::context c3 = c1; saga::context c4 = c0; c4 = c1; std::cout << "id 0 : " << c0.get_id () << std::endl; std::cout << "id 1 : " << c1.get_id () << std::endl; std::cout << "id 2 : " << c2.get_id () << std::endl; std::cout << "id 3 : " << c3.get_id () << std::endl; std::cout << "id 4 : " << c4.get_id () << std::endl; std::cout << "val 0 : " << c0.get_attribute ("testkey") << std::endl; std::cout << "val 1 : " << c1.get_attribute ("testkey") << std::endl; std::cout << "val 2 : " << c2.get_attribute ("testkey") << std::endl; std::cout << "val 3 : " << c3.get_attribute ("testkey") << std::endl; std::cout << "val 4 : " << c4.get_attribute ("testkey") << std::endl; saga::file f; } catch ( const saga::exception::base & e ) { std::cout << "Error: " << e.get_msg () << std::endl; } return 0; }
void test_transform_binary(ExPolicy policy, IteratorTag) { static_assert( hpx::parallel::execution::is_execution_policy<ExPolicy>::value, "hpx::parallel::execution::is_execution_policy<ExPolicy>::value"); typedef std::vector<int>::iterator base_iterator; typedef test::test_iterator<base_iterator, IteratorTag> iterator; std::vector<int> c1(10007); std::vector<int> c2(c1.size()); std::vector<int> d1(c1.size()); //-V656 std::iota(std::begin(c1), std::end(c1), std::rand()); std::iota(std::begin(c2), std::end(c2), std::rand()); auto result = hpx::parallel::transform(policy, iterator(std::begin(c1)), iterator(std::end(c1)), std::begin(c2), std::begin(d1), add()); HPX_TEST(hpx::util::get<0>(result) == iterator(std::end(c1))); HPX_TEST(hpx::util::get<1>(result) == std::end(c2)); HPX_TEST(hpx::util::get<2>(result) == std::end(d1)); // verify values std::vector<int> d2(c1.size()); std::transform(std::begin(c1), std::end(c1), std::begin(c2), std::begin(d2), add()); std::size_t count = 0; HPX_TEST(std::equal(std::begin(d1), std::end(d1), std::begin(d2), [&count](int v1, int v2) -> bool { HPX_TEST_EQ(v1, v2); ++count; return v1 == v2; })); HPX_TEST_EQ(count, d2.size()); }
void testAutomaticConnectionManagement() { std::cout << __FUNCTION__ << std::endl; std::cout << "---------------------------------" << std::endl; ItemProvider ip; Client c1(0); Client c2(1); ip.registerClient(c1); ip.registerClient(c2); { // boost::shared_ptr-managed pointer used auto c3 = boost::make_shared<Client>(2); ip.registerClient(c3); // std::shared_ptr-managed pointer used auto c4 = std::make_shared<Client>(3); ip.registerClient(c4); ip.notify(); } ip.notify(); std::cout << "---------------------------------" << std::endl; }
int main() { complex c1(8, 7); complex c2(2, 1); complex c3(1.3); // 生成一个临时的 complex 对象 cout << complex(1, 5) << endl; cout << c1 << endl; cout << c1 - c2 << endl; // 强制将 1.3 转为 complex 型,类似 int(1.3) c3 = c2 - complex(1.3); cout << c3 << endl; // 强制将坐标类转为 complex 型 point p1(10, -10); complex c4; c4 = complex(p1); cout << c4 << endl; return 0; }
void HUD::setup(){ //Colors for HUDSpinners below ofColor c(36,96,150); ofColor c2(36,180,150); ofColor c3(93,5,255); ofColor c4(254,173,69); ofColor c5(5,209,245); ofColor c6(40,240,60); spinner1.setup(10 /*count*/, 200.0 /*avgRotSpd*/, 100 /*rotVariation*/, c /*color*/, 30 /*resolution*/, 20 /*minRad*/, 55 /*maxRad*/, 15 /*minWidth*/, 30 /*maxWidth*/); spinner2.setup(10 /*count*/, 150 /*avgRotSpd*/, 50 /*rotVariation*/, c2 /*color*/, 40 /*resolution*/, 15 /*minRad*/, 55 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/); spinner3.setup(15 /*count*/, 150 /*avgRotSpd*/, 140 /*rotVariation*/, c3 /*color*/, 40 /*resolution*/, 20 /*minRad*/, 55 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/); spinner4.setup(15 /*count*/, 150 /*avgRotSpd*/, 140 /*rotVariation*/, c4 /*color*/, 40 /*resolution*/, 30 /*minRad*/, 55 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/); spinner5.setup(20 /*count*/, 150 /*avgRotSpd*/, 140 /*rotVariation*/, c5 /*color*/, 40 /*resolution*/, 20 /*minRad*/, 80 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/); spinner6.setup(15 /*count*/, -150 /*avgRotSpd*/, 100 /*rotVariation*/, c6 /*color*/, 40 /*resolution*/, 30 /*minRad*/, 200 /*maxRad*/, 20 /*minWidth*/, 100 /*maxWidth*/); HUDimg.loadImage("HUD3.png"); singleBlink = false; doubleBlink = false; }
void QFCompleterTextEditWidget::comment(){ QTextCursor c(textCursor()); if (c.selectionStart() == c.selectionEnd()) { c.movePosition(QTextCursor::StartOfLine); c.insertText(commentString+" "); //setTextCursor(c); } else { // now we have to iterate through all selected blocks (lines) and indent them QTextCursor c1(c); c1.setPosition(c.selectionStart()); QTextCursor c2(c); c2.setPosition(c.selectionEnd()); c1.beginEditBlock(); while (c1.blockNumber() <= c2.blockNumber()) { c1.movePosition(QTextCursor::StartOfBlock); c1.insertText(commentString+" "); if (!c1.movePosition(QTextCursor::NextBlock)) break; } c1.endEditBlock(); setTextCursor(c); } }
void Mesh::centerAlign() { Point c2(mAABB[0].max); Point c1(mAABB[0].min); c2.sub(c1); c2.scale(0.5); c1.add(c2); vector<Point>::iterator vi; for (vi=mVertices.begin(); vi!= mVertices.end(); ++vi) vi->sub(c1); vector<Box>::iterator pi; for(pi=mVoxels.begin(); pi!=mVoxels.end(); ++pi) pi->sub(c1); for (int bi=0; bi<BVL_SIZE(BVL); ++bi){ mAABB[bi].sub(c1); mSphere[bi].sub(c1); } updateTriangleData(); }
// remove subsumed clauses int removedSubsumed(List<Clause> &cl1, List<Clause> &cl2, List<Clause> &cl2rmv) { // check if any clauses in clause list 1 subsume any // clause in clause set 2. ListIterator<Clause> cl2Iter(cl2); for ( ; !cl2Iter.done(); cl2Iter++) { ListIterator<Clause> cl1Iter(cl1); for ( ; !cl1Iter.done(); cl1Iter++) { Substitutions s; Clause c1(cl1Iter()); Clause c2(cl2Iter()); if (subsumes(c1, c2, s) == OK) { if (cl2rmv.insertAtEnd(cl2Iter()) != OK) return(NOTOK); } } } return(OK); }
TEST(myCollectioncircle, myCollection){ std::stringstream ss; myCollection<Circle> circleCollection; CHECK(circleCollection.isEmpty()); Circle c1(5, 2, 4, "c1"); Circle c2(4, 2, 4, "c2"); Circle c3(3, 2, 4, "c3"); Circle c4(2, 2, 4, "c4"); circleCollection.add(c1); circleCollection.add(c2); circleCollection.add(c3); circleCollection.add(c4); CHECK_EQUAL(circleCollection.count(), 4); circleCollection.printAll(ss); CHECK_EQUAL("name: c1, radius: 5, x: 2, y: 4name: c2, radius: 4, x: 2, y: 4name: c3, radius: 3, x: 2, y: 4name: c4, radius: 2, x: 2, y: 4", ss.str()); ss.str(""); circleCollection.printReverseOrder(ss); CHECK_EQUAL("name: c4, radius: 2, x: 2, y: 4name: c3, radius: 3, x: 2, y: 4name: c2, radius: 4, x: 2, y: 4name: c1, radius: 5, x: 2, y: 4", ss.str()); }
void CAirCAI::ExecuteGuard(Command& c) { assert(owner->unitDef->canGuard); const CUnit* guardee = unitHandler->GetUnit(c.params[0]); if (guardee == NULL) { FinishCommand(); return; } if (UpdateTargetLostTimer(guardee->id) == 0) { FinishCommand(); return; } if (guardee->outOfMapTime > (GAME_SPEED * 5)) { FinishCommand(); return; } const bool pushAttackCommand = (owner->maxRange > 0.0f) && owner->unitDef->canAttack && ((guardee->lastAttackFrame + 40) < gs->frameNum) && IsValidTarget(guardee->lastAttacker); if (pushAttackCommand) { Command nc(CMD_ATTACK, c.options | INTERNAL_ORDER, guardee->lastAttacker->id); commandQue.push_front(nc); SlowUpdate(); } else { Command c2(CMD_MOVE, c.options | INTERNAL_ORDER); c2.timeOut = gs->frameNum + 60; if (guardee->pos.IsInBounds()) { c2.PushPos(guardee->pos); } else { float3 clampedGuardeePos = guardee->pos; clampedGuardeePos.ClampInBounds(); c2.PushPos(clampedGuardeePos); } commandQue.push_front(c2); } }
void CTransportCAI::UnloadUnits_LandFlood(Command& c, CTransportUnit* transport) { if (lastCall == gs->frameNum) { // avoid infinite loops return; } lastCall = gs->frameNum; if (static_cast<CTransportUnit*>(owner)->GetTransportedUnits().empty()) { FinishCommand(); return; } float3 pos = c.GetPos(0); float3 found; const CTransportUnit* ownerTrans = static_cast<CTransportUnit*>(owner); const std::list<CTransportUnit::TransportedUnit>& transportees = ownerTrans->GetTransportedUnits(); const CUnit* transportee = transportees.front().unit; const float radius = c.params[3]; const float spread = transportee->radius * ownerTrans->unitDef->unloadSpread; const bool canUnload = FindEmptySpot(pos, radius, spread, found, transportee); if (canUnload) { Command c2(CMD_UNLOAD_UNIT, c.options | INTERNAL_ORDER, found); commandQue.push_front(c2); if (isFirstIteration) { Command c1(CMD_MOVE, c.options | INTERNAL_ORDER, pos); commandQue.push_front(c1); startingDropPos = pos; } SlowUpdate(); return; } else { FinishCommand(); } }
Coord Coord::operator *(Quat &q) { // From http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/ Coord c2(0.0f, 0.0f, 0.0f); c2.X = q.W * q.W * X + 2.0f * q.Y * q.W * Z - 2.0f * q.Z * q.W * Y + q.X * q.X * X + 2.0f * q.Y * q.X * Y + 2.0f * q.Z * q.X * Z - q.Z * q.Z * X - q.Y * q.Y * X; c2.Y = 2.0f * q.X * q.Y * X + q.Y * q.Y * Y + 2.0f * q.Z * q.Y * Z + 2.0f * q.W * q.Z * X - q.Z * q.Z * Y + q.W * q.W * Y - 2.0f * q.X * q.W * Z - q.X * q.X * Y; c2.Z = 2.0f * q.X * q.Z * X + 2.0f * q.Y * q.Z * Y + q.Z * q.Z * Z - 2.0f * q.W * q.Y * X - q.Y * q.Y * Z + 2.0f * q.W * q.X * Y - q.X * q.X * Z + q.W * q.W * Z; return c2; }
void PlotCartesianWidget::drawLabels() { glf->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glf->glEnable(GL_BLEND); glf->glBindVertexArray(textVAO); glm::vec3 c1(0.6,0.6,0.6); glm::vec3 c2(0.3,0.3,0.3); renderText( 0.0, -0.52 * 33.33 / height(), "0", c1 ); renderText( 0.785398163-0.02*lookZoom, -0.52 * 33.33 / height(), "45", c1 ); renderText( 1.57079633-0.02*lookZoom, -0.52 * 33.33 / height(), "90", c1 ); renderText( -0.785398163-0.02*lookZoom, -0.52 * 33.33 / height(), "45", c1 ); renderText( -1.57079633-0.02*lookZoom, -0.52 * 33.33 / height(), "90", c1 ); float zoomY = lookZoom * 1.0f/scaleY; if (zoomY < zoomLevel[0]) { for( int i = 1; i < 5; i++) renderText( 0.05-0.005*lookZoom, float(i)*0.2-0.02*lookZoom, QString::number(i*0.2), c1 ); if (zoomY < zoomLevel[1]) { for( int i = 0; i < 5; i++) renderText( 0.05-0.005*lookZoom, 0.1+float(i)*0.2-0.02*lookZoom, QString::number(0.1+i*0.2), c1 ); if (zoomY < zoomLevel[2]) { for( int i = 0; i < 10; i++) renderText( 0.05-0.005*lookZoom, 0.05+float(i)*0.1-0.02*lookZoom, QString::number(0.05+i*0.1), c1 ); } } } for( int i = 1; i <= 9; i++ ) renderText( 0.05-0.005*lookZoom, float(i)-0.02*lookZoom, QString::number(i), c2 ); for( int i = 10; i <= 100; i += 10 ) renderText( -0.05-0.005*lookZoom, float(i), QString::number(i), c2 ); glf->glBindVertexArray(0); glf->glDisable(GL_BLEND); glf->glBindBuffer(GL_ARRAY_BUFFER, 0); }
// @bug 4051866 // // Collator -> rules -> Collator round-trip broken for expanding characters // void CollationRegressionTest::Test4051866(/* char* par */) { UnicodeString rules; UErrorCode status = U_ZERO_ERROR; rules += "&n < o "; rules += "& oe ,o"; rules += (UChar)0x3080; rules += "& oe ,"; rules += (UChar)0x1530; rules += " ,O"; rules += "& OE ,O"; rules += (UChar)0x3080; rules += "& OE ,"; rules += (UChar)0x1520; rules += "< p ,P"; // Build a collator containing expanding characters LocalPointer<RuleBasedCollator> c1(new RuleBasedCollator(rules, status), status); if (U_FAILURE(status)) { errln("RuleBasedCollator(rule string) failed - %s", u_errorName(status)); return; } // Build another using the rules from the first LocalPointer<RuleBasedCollator> c2(new RuleBasedCollator(c1->getRules(), status), status); if (U_FAILURE(status)) { errln("RuleBasedCollator(rule string from other RBC) failed - %s", u_errorName(status)); return; } // Make sure they're the same if (!(c1->getRules() == c2->getRules())) { errln("Rules are not equal"); } }
int test27 (void) { int ret = 0; printf ("TEST: ltrim(), rtrim() methods\n"); try { CBString c0, c1(" Test "), c2(" "); printf ("\t\"%s\".ltrim ()\n", (const char *) c0); c0.ltrim (); ret += c0 != ""; c0 = ""; c0.rtrim (); ret += c0 != ""; printf ("\t\"%s\".ltrim ()\n", (const char *) c1); c1.ltrim (); ret += c1 != "Test "; c1 = " Test "; c1.rtrim (); ret += c1 != " Test"; printf ("\t\"%s\".ltrim ()\n", (const char *) c2); c2.ltrim (); ret += c2 != ""; c2 = " "; c2.rtrim (); ret += c2 != ""; } catch (struct CBStringException err) { printf ("Exception thrown [%d]: %s\n", __LINE__, err.what()); ret ++; } printf ("\t# failures: %d\n", ret); return ret; }
void QFCompleterTextEditWidget::uncomment(){ QTextCursor c(textCursor()); if (c.selectionStart() == c.selectionEnd()) { c.select(QTextCursor::LineUnderCursor); c.insertText(removeComments(c.selectedText())); //setTextCursor(c); } else { // now we have to iterate through all selected blocks (lines) and indent them QTextCursor c1(c); c1.setPosition(c.selectionStart()); QTextCursor c2(c); c2.setPosition(c.selectionEnd()); c1.beginEditBlock(); while (c1.blockNumber() <= c2.blockNumber()) { c1.select(QTextCursor::BlockUnderCursor); //std::cout<<"'"<<c1.selectedText().toLatin1().data()<<"' => '"<<removeComments(c1.selectedText()).toLatin1().data()<<"'"<<std::endl; c1.insertText(removeComments(c1.selectedText())); if (!c1.movePosition(QTextCursor::NextBlock)) break; } c1.endEditBlock(); setTextCursor(c); } }
void tst_QuickPath::line() { QQmlEngine engine; QQmlComponent c1(&engine); c1.setData( "import QtQuick 2.0\n" "Path {\n" "startX: 0; startY: 0\n" "PathLine { x: 100; y: 100 }\n" "}", QUrl()); QScopedPointer<QObject> o1(c1.create()); QQuickPath *path1 = qobject_cast<QQuickPath *>(o1.data()); QVERIFY(path1); QQmlComponent c2(&engine); c2.setData( "import QtQuick 2.0\n" "Path {\n" "startX: 0; startY: 0\n" "PathLine { x: 50; y: 50 }\n" "PathLine { x: 100; y: 100 }\n" "}", QUrl()); QScopedPointer<QObject> o2(c2.create()); QQuickPath *path2 = qobject_cast<QQuickPath *>(o2.data()); QVERIFY(path2); for (int i = 0; i < 167; ++i) { qreal t = i / 167.0; QPointF p1 = path1->pointAt(t); QCOMPARE(p1.x(), p1.y()); QPointF p2 = path2->pointAt(t); QCOMPARE(p1.toPoint(), p2.toPoint()); } }
TEST_F(TrackerTest, reply) { EXPECT_CALL(mockSocketUDP,send(_)).Times(1); EXPECT_CALL(mockSocketTCP,sendMsg(_)).Times(0); Client c(&mockSocketUDP); t->reply(&c); Mock::VerifyAndClearExpectations(&mockSocketUDP); Mock::VerifyAndClearExpectations(&mockSocketTCP); EXPECT_CALL(mockSocketUDP,send(_)).Times(0); EXPECT_CALL(mockSocketTCP,sendMsg(_)).Times(1); Client c2(&mockSocketTCP); t->reply(&c2); Mock::VerifyAndClearExpectations(&mockSocketUDP); Mock::VerifyAndClearExpectations(&mockSocketTCP); EXPECT_CALL(mockSocketUDP,send(_)).Times(0); EXPECT_CALL(mockSocketTCP,sendMsg(_)).Times(0); t->reply(NULL); }
void test_transform_binary2_async(ExPolicy p, IteratorTag) { typedef std::vector<int>::iterator base_iterator; typedef test::test_iterator<base_iterator, IteratorTag> iterator; std::vector<int> c1(10007); std::vector<int> c2(c1.size()); std::vector<int> d1(c1.size()); //-V656 std::iota(boost::begin(c1), boost::end(c1), std::rand()); std::iota(boost::begin(c2), boost::end(c2), std::rand()); auto f = hpx::parallel::transform(p, iterator(boost::begin(c1)), iterator(boost::end(c1)), boost::begin(c2), boost::end(c2), boost::begin(d1), add()); f.wait(); hpx::util::tuple<iterator, base_iterator, base_iterator> result = f.get(); HPX_TEST(hpx::util::get<0>(result) == iterator(boost::end(c1))); HPX_TEST(hpx::util::get<1>(result) == boost::end(c2)); HPX_TEST(hpx::util::get<2>(result) == boost::end(d1)); // verify values std::vector<int> d2(c1.size()); std::transform(boost::begin(c1), boost::end(c1), boost::begin(c2), boost::begin(d2), add()); std::size_t count = 0; HPX_TEST(std::equal(boost::begin(d1), boost::end(d1), boost::begin(d2), [&count](int v1, int v2) -> bool { HPX_TEST_EQ(v1, v2); ++count; return v1 == v2; })); HPX_TEST_EQ(count, d2.size()); }
void Character::resizeGL(int w, int h) { //This code sets the concatenated view and perspective projection matrices used for //our scene's camera view. // vvv TODO REPLACE THIS CODE IN HW2 glm::vec4 c1(1.1933f, 0, 1.1933f, 0); glm::vec4 c2(0.9856f, 1.9712f, -0.9856f, 0); glm::vec4 c3(0.5785f, -0.5785f, -0.5785f, 11.9484f); glm::vec4 c4(0.5774f, -0.5774f, -0.5774f, 12.1244f); glm::mat4 viewproj(c1, c2, c3, c4); viewproj = glm::transpose(viewproj); // ^^^ TODO REPLACE THIS CODE IN HW2 // Upload the view-projection matrix to our shaders (i.e. onto the graphics card) QMatrix4x4 qviewproj = la::to_qmat(viewproj); prog_lambert.prog.bind(); prog_lambert.prog.setUniformValue(prog_lambert.unifViewProj, qviewproj); prog_wire.prog.bind(); prog_wire.prog.setUniformValue(prog_wire.unifViewProj, qviewproj); printGLErrorLog(); }
bool path_intersects_path(PathIterator& p1, PathIterator& p2) { typedef agg::conv_curve<PathIterator> curve_t; if (p1.total_vertices() < 2 || p2.total_vertices() < 2) { return false; } curve_t c1(p1); curve_t c2(p2); double x11, y11, x12, y12; double x21, y21, x22, y22; c1.vertex(&x11, &y11); while (c1.vertex(&x12, &y12) != agg::path_cmd_stop) { c2.rewind(0); c2.vertex(&x21, &y21); while (c2.vertex(&x22, &y22) != agg::path_cmd_stop) { if (segments_intersect(x11, y11, x12, y12, x21, y21, x22, y22)) { return true; } x21 = x22; y21 = y22; } x11 = x12; y11 = y12; } return false; }
std::pair<QPointF, QPointF> ConnectionGeometry:: pointsC1C2() const { double xDistance = _in.x() - _out.x(); //double yDistance = _in.y() - _out.y() - 100; double defaultOffset = 200; double minimum = qMin(defaultOffset, std::abs(xDistance)); double verticalOffset = 0; double ratio1 = 0.5; if (xDistance <= 0) { verticalOffset = -minimum; ratio1 = 1.0; } //double verticalOffset2 = verticalOffset; //if (xDistance <= 0) //verticalOffset2 = qMin(defaultOffset, std::abs(yDistance)); //auto sign = [](double d) { return d > 0.0 ? +1.0 : -1.0; }; //verticalOffset2 = 0.0; QPointF c1(_out.x() + minimum * ratio1, _out.y() + verticalOffset); QPointF c2(_in.x() - minimum * ratio1, _in.y() + verticalOffset); return std::make_pair(c1, c2); }
void QwtPainter::drawRoundedFrame( QPainter *painter, const QRectF &rect, double xRadius, double yRadius, const QPalette &palette, int lineWidth, int frameStyle ) { painter->save(); painter->setRenderHint( QPainter::Antialiasing, true ); painter->setBrush( Qt::NoBrush ); double lw2 = lineWidth * 0.5; QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 ); QPainterPath path; path.addRoundedRect( r, xRadius, yRadius ); enum Style { Plain, Sunken, Raised }; Style style = Plain; if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken ) style = Sunken; else if ( (frameStyle & QFrame::Raised) == QFrame::Raised ) style = Raised; if ( style != Plain && path.elementCount() == 17 ) { // move + 4 * ( cubicTo + lineTo ) QPainterPath pathList[8]; for ( int i = 0; i < 4; i++ ) { const int j = i * 4 + 1; pathList[ 2 * i ].moveTo( path.elementAt(j - 1).x, path.elementAt( j - 1 ).y ); pathList[ 2 * i ].cubicTo( path.elementAt(j + 0).x, path.elementAt(j + 0).y, path.elementAt(j + 1).x, path.elementAt(j + 1).y, path.elementAt(j + 2).x, path.elementAt(j + 2).y ); pathList[ 2 * i + 1 ].moveTo( path.elementAt(j + 2).x, path.elementAt(j + 2).y ); pathList[ 2 * i + 1 ].lineTo( path.elementAt(j + 3).x, path.elementAt(j + 3).y ); } QColor c1( palette.color( QPalette::Dark ) ); QColor c2( palette.color( QPalette::Light ) ); if ( style == Raised ) qSwap( c1, c2 ); for ( int i = 0; i < 4; i++ ) { QRectF r = pathList[2 * i].controlPointRect(); QPen arcPen; arcPen.setCapStyle( Qt::FlatCap ); arcPen.setWidth( lineWidth ); QPen linePen; linePen.setCapStyle( Qt::FlatCap ); linePen.setWidth( lineWidth ); switch( i ) { case 0: { arcPen.setColor( c1 ); linePen.setColor( c1 ); break; } case 1: { QLinearGradient gradient; gradient.setStart( r.topLeft() ); gradient.setFinalStop( r.bottomRight() ); gradient.setColorAt( 0.0, c1 ); gradient.setColorAt( 1.0, c2 ); arcPen.setBrush( gradient ); linePen.setColor( c2 ); break; } case 2: { arcPen.setColor( c2 ); linePen.setColor( c2 ); break; } case 3: { QLinearGradient gradient; gradient.setStart( r.bottomRight() ); gradient.setFinalStop( r.topLeft() ); gradient.setColorAt( 0.0, c2 ); gradient.setColorAt( 1.0, c1 ); arcPen.setBrush( gradient ); linePen.setColor( c1 ); break; } } painter->setPen( arcPen ); painter->drawPath( pathList[ 2 * i] ); painter->setPen( linePen ); painter->drawPath( pathList[ 2 * i + 1] ); } } else { QPen pen( palette.color( QPalette::WindowText ), lineWidth ); painter->setPen( pen ); painter->drawPath( path ); } painter->restore(); }
int main() { { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; C c1(0, Hash(1), Compare(1), Alloc(1)); C c2(0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() == 0); assert(c1.size() == 0); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(1)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() == 0); assert(c2.size() == 0); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(2)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; P a2[] = { P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80) }; C c1(0, Hash(1), Compare(1), Alloc(1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() >= 11); assert(c1.size() == 8); assert(*c1.find(10) == 10); assert(*c1.find(20) == 20); assert(*c1.find(30) == 30); assert(*c1.find(40) == 40); assert(*c1.find(50) == 50); assert(*c1.find(60) == 60); assert(*c1.find(70) == 70); assert(*c1.find(80) == 80); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(1)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() == 0); assert(c2.size() == 0); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(2)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; P a1[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); C c2(0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() == 0); assert(c1.size() == 0); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(1)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() >= 7); assert(c2.size() == 6); assert(c2.count(1) == 2); assert(c2.count(2) == 2); assert(c2.count(3) == 1); assert(c2.count(4) == 1); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(2)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef test_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; P a1[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; P a2[] = { P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80) }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() >= 11); assert(c1.size() == 8); assert(*c1.find(10) == 10); assert(*c1.find(20) == 20); assert(*c1.find(30) == 30); assert(*c1.find(40) == 40); assert(*c1.find(50) == 50); assert(*c1.find(60) == 60); assert(*c1.find(70) == 70); assert(*c1.find(80) == 80); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(1)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() >= 7); assert(c2.size() == 6); assert(c2.count(1) == 2); assert(c2.count(2) == 2); assert(c2.count(3) == 1); assert(c2.count(4) == 1); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(2)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; C c1(0, Hash(1), Compare(1), Alloc(1)); C c2(0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() == 0); assert(c1.size() == 0); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(2)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() == 0); assert(c2.size() == 0); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(1)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; P a2[] = { P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80) }; C c1(0, Hash(1), Compare(1), Alloc(1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() >= 11); assert(c1.size() == 8); assert(*c1.find(10) == 10); assert(*c1.find(20) == 20); assert(*c1.find(30) == 30); assert(*c1.find(40) == 40); assert(*c1.find(50) == 50); assert(*c1.find(60) == 60); assert(*c1.find(70) == 70); assert(*c1.find(80) == 80); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(2)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() == 0); assert(c2.size() == 0); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(1)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; P a1[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); C c2(0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() == 0); assert(c1.size() == 0); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(2)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() >= 7); assert(c2.size() == 6); assert(c2.count(1) == 2); assert(c2.count(2) == 2); assert(c2.count(3) == 1); assert(c2.count(4) == 1); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(1)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } { typedef test_hash<std::hash<int> > Hash; typedef test_compare<std::equal_to<int> > Compare; typedef other_allocator<int> Alloc; typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; typedef int P; P a1[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; P a2[] = { P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80) }; C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); c2.max_load_factor(2); c1.swap(c2); assert(c1.bucket_count() >= 11); assert(c1.size() == 8); assert(*c1.find(10) == 10); assert(*c1.find(20) == 20); assert(*c1.find(30) == 30); assert(*c1.find(40) == 40); assert(*c1.find(50) == 50); assert(*c1.find(60) == 60); assert(*c1.find(70) == 70); assert(*c1.find(80) == 80); assert(c1.hash_function() == Hash(2)); assert(c1.key_eq() == Compare(2)); assert(c1.get_allocator() == Alloc(2)); assert(std::distance(c1.begin(), c1.end()) == c1.size()); assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); assert(c1.max_load_factor() == 2); assert(c2.bucket_count() >= 7); assert(c2.size() == 6); assert(c2.count(1) == 2); assert(c2.count(2) == 2); assert(c2.count(3) == 1); assert(c2.count(4) == 1); assert(c2.hash_function() == Hash(1)); assert(c2.key_eq() == Compare(1)); assert(c2.get_allocator() == Alloc(1)); assert(std::distance(c2.begin(), c2.end()) == c2.size()); assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); assert(c2.max_load_factor() == 1); } }
int U_EXPORT main (int argc, char* argv[]) { U_ULIB_INIT(argv); U_TRACE(5,"main(%d)",argc) UString value, path, domain, port, not_found; HttpCookie c1(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM("Name=value")), c2(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_2)), c5(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_5)); U_ASSERT( c5.find(U_STRING_FROM_CONSTANT("otptoken"), value, path, domain, port) == true ) U_ASSERT( value == U_STRING_FROM_CONSTANT("pluto") ) U_ASSERT( c1.count(U_STRING_FROM_CONSTANT("Name")) == 1 ) U_ASSERT( c2.count(U_STRING_FROM_CONSTANT("$Domain")) == 2 ) U_ASSERT( c1.find(U_STRING_FROM_CONSTANT("Name"), value, path, domain, port) == true ) U_ASSERT( value == U_STRING_FROM_CONSTANT("value") ) U_ASSERT( path == not_found ) U_ASSERT( domain == not_found ) U_ASSERT( port == not_found ) U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("NameB"), value, path, domain, port) == true ) U_ASSERT( value == U_STRING_FROM_CONSTANT("ValueB") ) U_ASSERT( domain == U_STRING_FROM_CONSTANT("domain1") ) U_ASSERT( port == not_found ) #ifdef SERGIO U_ASSERT( path == U_STRING_FROM_CONSTANT("/") ) #else U_ASSERT( path == U_STRING_FROM_CONSTANT("\"/\"") ) #endif U_ASSERT( c2.del(U_STRING_FROM_CONSTANT("NameB")) == true ) value = path = domain = port = not_found; U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("Name"), value, path, domain, port) == false ) U_ASSERT( value == not_found ) U_ASSERT( path == not_found ) U_ASSERT( domain == not_found ) U_ASSERT( port == not_found ) U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("NameC"), value, path, domain, port) == true ) U_ASSERT( value == U_STRING_FROM_CONSTANT("ValueC") ) U_ASSERT( path == U_STRING_FROM_CONSTANT("domain1") ) #ifdef SERGIO U_ASSERT( port == U_STRING_FROM_CONSTANT("123") ) U_ASSERT( domain == U_STRING_FROM_CONSTANT("/") ) #else U_ASSERT( port == U_STRING_FROM_CONSTANT("\"123\"") ) U_ASSERT( domain == U_STRING_FROM_CONSTANT("\"/\"") ) #endif HttpSetCookie s1(U_CONSTANT_TO_PARAM("Set-Cookie"), U_CONSTANT_TO_PARAM(SETCOOKIE_1)), s2(U_CONSTANT_TO_PARAM("Set-Cookie2"), U_CONSTANT_TO_PARAM(SETCOOKIE_2)); U_ASSERT( s1.count(U_STRING_FROM_CONSTANT("Domain")) == 2 ) U_ASSERT( s2.count(U_STRING_FROM_CONSTANT("Port")) == 1 ) HttpCookie c3(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_AUTH) ); U_ASSERT( c3.count(U_STRING_FROM_CONSTANT("AUTHTOKEN")) == 1 ) value = path = domain = port = not_found; U_ASSERT( c3.find(U_STRING_FROM_CONSTANT("AUTHTOKEN"), value, path, domain, port) == true ) U_ASSERT( path == not_found ) U_ASSERT( domain == not_found ) U_ASSERT( port == not_found ) value.erase(value.size()-1, 1); value.erase(0, 1); #ifdef U_PROXY_UNIT DES3engine eng("pippo"); OtpAuthToken a(&eng, value); #else u_des3_key("pippo"); OtpAuthToken a(0, value); #endif U_ASSERT( a.tid == U_STRING_FROM_CONSTANT("Current_Server_ID") ) U_ASSERT( a.uid == U_STRING_FROM_CONSTANT("User_ID") ) U_ASSERT( a.sid == U_STRING_FROM_CONSTANT("Session_ID") ) U_ASSERT( a.ts == U_STRING_FROM_CONSTANT("20031125131800") ) U_ASSERT( a.cf == U_STRING_FROM_CONSTANT("codicefiscale1") ) U_ASSERT( a.migrate == true ) HttpHeader h; HttpField* f = new HttpField(U_STRING_FROM_CONSTANT("Content-Type"), U_STRING_FROM_CONSTANT(" application/x-www-form-urlencoded")); HttpBaAuthorization* ba = new HttpBaAuthorization(U_CONSTANT_TO_PARAM("Authorization"), U_CONSTANT_TO_PARAM(" Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==")); HttpBaAuthorization* ba1 = new HttpBaAuthorization(U_CONSTANT_TO_PARAM("Authorization"), U_CONSTANT_TO_PARAM(" Basic dXRlbnRlMTpzaWQx")); h.add(ba); h.add(f); h.add(ba1); HttpOtpPostLogin p(U_CONSTANT_TO_PARAM(POST_BODY), U_STRING_FROM_CONSTANT("user"), U_STRING_FROM_CONSTANT("pin"), U_STRING_FROM_CONSTANT("token"), U_STRING_FROM_CONSTANT("password"), U_STRING_FROM_CONSTANT("cf"), h); U_ASSERT( p.user == U_STRING_FROM_CONSTANT("stefano casazza") ) U_ASSERT( p.pin == U_STRING_FROM_CONSTANT("12345") ) U_ASSERT( p.token == U_STRING_FROM_CONSTANT("autorizzativo") ) HttpField* p1 = h.del(U_STRING_FROM_CONSTANT("Content-Type")); U_ASSERT( p1 != 0 ) U_ASSERT( p1 == f ) HttpBaAuthorization* p2 = (HttpBaAuthorization*) h.find(U_STRING_FROM_CONSTANT("Authorization")); U_ASSERT( p2 != 0 ) U_ASSERT( p2 == ba ) U_ASSERT( p2->user == U_STRING_FROM_CONSTANT("Aladdin") ) U_ASSERT( p2->passwd == U_STRING_FROM_CONSTANT("open sesame") ) HttpBaAuthorization* p3 = (HttpBaAuthorization*) h.find(U_STRING_FROM_CONSTANT("Authorization"), 1); U_ASSERT( p3 != 0 ) U_ASSERT( p3 == ba1 ) U_ASSERT( p3->user == U_STRING_FROM_CONSTANT("utente1") ) U_ASSERT( p3->passwd == U_STRING_FROM_CONSTANT("sid1") ) h.clear(); UString result; a.stringify(result); // TID=trustACCESS1;UID=utente1;SID=;TS=20031201174127;CF=codicefiscale1 # define COOKIE_AUTH_1 \ "U2FsdGVkX1/QsrBvmsVHx0rrX78ldh6IJu1+4GhKoJ9O5ETSbfSiDip1gszkZX7w5ah6vkYfRWI8271LcNKhUsZVehRoscudLO8uotQgeiiF1B46ITphGw==" // TID=trustACCESS1;UID=utente1;SID=sid;TS=20031201174127;CF=codicefiscale1;HP1=Profile_Header1;HPn=Profile_Headern;MIGRATE # define COOKIE_AUTH_2 \ "U2FsdGVkX1+tUkpPi14NVlKhm5KUFbSH0JFvi23+8B75MnKgtyD/sc0hc0ESmSahiYozVbS6a3OoZfWDHX3G3zuUwCP7n1+3jXK0wu6niifYUW+cKBk1WUdpJZd0xjJernDsWtPfq9j30uatAhHULG57vdrKlbtxM/EIaiaUow1AeLuDiZDcTRonghpI/aaz" #ifdef U_PROXY_UNIT DES3engine eng1("password"); OtpAuthToken c(&eng1, U_STRING_FROM_CONSTANT(COOKIE_AUTH_2)); DES3engine eng2("password"); OtpAuthToken b(&eng2, U_STRING_FROM_CONSTANT(COOKIE_AUTH_1)); #else u_des3_key("password"); OtpAuthToken c(0, U_STRING_FROM_CONSTANT(COOKIE_AUTH_2)); u_des3_reset(); OtpAuthToken b(0, U_STRING_FROM_CONSTANT(COOKIE_AUTH_1)); #endif U_ASSERT( b.is_valid() == false ) U_ASSERT( c.is_valid() == true ) U_ASSERT( c.tid == U_STRING_FROM_CONSTANT("trustACCESS1") ) U_ASSERT( c.uid == U_STRING_FROM_CONSTANT("utente1") ) U_ASSERT( c.sid == U_STRING_FROM_CONSTANT("sid") ) U_ASSERT( c.ts == U_STRING_FROM_CONSTANT("20031201174127") ) U_ASSERT( c.cf == U_STRING_FROM_CONSTANT("codicefiscale1") ) U_ASSERT( c.migrate == true ) value = not_found; U_ASSERT( c.find(U_STRING_FROM_CONSTANT("HP1"), value) == true ) U_ASSERT( value == U_STRING_FROM_CONSTANT("Profile_Header1") ) U_ASSERT( c.del(U_STRING_FROM_CONSTANT("HP1")) == true ) value = not_found; U_ASSERT( c.find(U_STRING_FROM_CONSTANT("HPn"), value) == true ) U_ASSERT( value == U_STRING_FROM_CONSTANT("Profile_Headern") ) HttpCookie c4(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_PROBLEM) ); U_ASSERT( c4.count(U_STRING_FROM_CONSTANT("otptoken")) == 1 ) value = path = domain = port = not_found; U_ASSERT( c4.find(U_STRING_FROM_CONSTANT("otptoken"), value, path, domain, port) == true ) value.erase(value.size()-1, 1); value.erase(0, 1); #ifdef U_PROXY_UNIT DES3engine eng3("password"); OtpAuthToken d(&eng3, value); #else u_des3_reset(); OtpAuthToken d(0, value); #endif U_ASSERT( d.is_valid() == false ) result.erase(result.size()-1, 1); result.erase(0, 1); cout.write(result.data(), result.size()); }
int Generate_Model_ANCFCable2D_contact(MBS* mbs) { ElementDataContainer* edc = mbs->GetModelDataContainer(); int nel = edc->TreeGetInt("Geometry.n_fibers"); double sx = edc->TreeGetDouble("Geometry.length"); double sy = edc->TreeGetDouble("Geometry.width"); int nx = edc->TreeGetInt("Geometry.nx"); int ny = edc->TreeGetInt("Geometry.ny"); double rho = edc->TreeGetDouble("Geometry.rho"); double Em = edc->TreeGetDouble("Geometry.Em"); double nu = edc->TreeGetDouble("Geometry.nu"); double box_x = edc->TreeGetDouble("Geometry.box_x"); double box_y = edc->TreeGetDouble("Geometry.box_y"); int nbox_x = edc->TreeGetInt("Geometry.nres_x"); int nbox_y = edc->TreeGetInt("Geometry.nres_y"); Vector3D size(sx,sy,1.0); double cdim = sy/2; double wi = 1; //width of GeomLine2D elements (in pts/pixel) //===============================2D fibers========================================= ANCFCable2D cable(mbs); Vector xc1(4); Vector xc2(4); double phi = -MY_PI/4.; xc1(1)=0.5*sx*cos(phi+MY_PI); xc1(2)=0.5*sx*sin(phi+MY_PI); xc1(3)=cos(phi); xc1(4)=sin(phi); xc2(1)=xc1(1)+sx*cos(phi); xc2(2)=xc1(2)+sx*sin(phi); xc2(3)=cos(phi); xc2(4)=sin(phi); //Material m1(mbs,rho,Em,nu); //int mat1 = mbs->AddMaterial(&m1); cable.SetANCFCable2D(xc1, xc2, rho, Em, size, Vector3D(0.,0.7,0.)); //cable.SetANCFCable2D(xc1, xc2, vcenter, vcenter, n1, n2, rho, Em, size, Vector3D(0.,0.7,0.)); int nr = mbs->AddElement(&cable); MBSLoad grav; grav.SetBodyLoad(-9.81*rho,2); mbs->GetElement(nr).AddLoad(grav); //MBSSensor force_x(mbs,TMBSSensor(TSElement+TSDOF),idx1,1); //measure force via Lagrange multiplier //force_x.SetSensorName(mystr("Node_")+mystr(i)+mystr("_force_x")); //mbs->AddSensor(&force_x); TArray<Vector2D> points; double dx = sx/nx; double dy = sy/ny; for(int i=0; i<nx; ++i) points.Add(Vector2D(-0.5*sx+i*dx,-0.5*sy)); for(int i=0; i<ny; ++i) points.Add(Vector2D(0.5*sx,-0.5*sy+i*dy)); for(int i=0; i<nx; ++i) points.Add(Vector2D(0.5*sx-i*dx,0.5*sy)); for(int i=0; i<=ny; ++i) points.Add(Vector2D(-0.5*sx,0.5*sy-i*dy)); //mbs->GetElement(nr).SetAltShape(1); ////sensors for nodal positions and velocities //MBSSensor s1(mbs,TMBSSensor(TSElement+TSplanar+TSPos+TSX),nr,Vector3D(-0.5*size.X(),0.,0.)); //s1.SetSensorName(mystr("Node_")+mystr(i)+mystr("_x")); //mbs->AddSensor(&s1); //sensors //field variables not available? //{ // FieldVariableElementSensor s1(mbs); // s1.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.)); // s1.SetSensorName(mystr("cable")+mystr("_x")); // mbs->AddSensor(&s1); // FieldVariableElementSensor s2(mbs); // s2.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.)); // s2.SetSensorName(mystr("cable")+mystr("_y")); // mbs->AddSensor(&s2); // FieldVariableElementSensor s3(mbs); // s3.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.)); // s3.SetSensorName(mystr("cable")+mystr("_vx")); // mbs->AddSensor(&s3); // FieldVariableElementSensor s4(mbs); // s4.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.)); // s4.SetSensorName(mystr("cable")+mystr("_vy")); // mbs->AddSensor(&s4); //} //contact Vector3D contactcol(0.5,0,0.5); int slaveNODEmode = 0; //if NODEmode = 1, then use locnodenumbers, if NODEmode==0 then use loccoords double bordersize = 0.25*sy; //additional search radius for master and slave segments/nodes GeneralContact2D gc(mbs, slaveNODEmode, bordersize, Vector3D(0.0005,0,0), contactcol); gc.SetContactMode(0); //0 for Hertzian contact with restitution coefficient gc.SetIsLagrange(0); double friccoeff = 0.2; gc.SetFriction(1, edc->TreeGetDouble("Geometry.friction_coeff")); gc.SetContactParams(edc->TreeGetDouble("Geometry.restitution_coeff"),1); //coefficient of restitution, Hertzian contact parameter gc.SetContactMaxDist(0.5*sy); //max penetration; if exceeded, it is treated as if there where no contact gc.SetSearchTreeDim(20,20); double cstiff = edc->TreeGetDouble("Geometry.contact_stiffness"); int bodyind = 1; for(int i=1; i<points.Length(); ++i) { gc.AddSlaveNode(nr, points(i), cstiff, bodyind); } if(edc->TreeGetInt("Geometry.mutual_contact")) { for(int i=1; i<points.Length(); ++i) { gc.AddMasterSegment(nr,points(i),points(i+1),bodyind); //be careful with orientation of master segments } } //===============================rigid body==================================== { Vector x0i(6); x0i(1)=0.; x0i(2)=0.25*box_y; x0i(3)=0.; x0i(4)=0.; x0i(5)=0.; x0i(6)=0.; double r0=0.3*sx; Vector3D sizei(r0,r0,1.); Vector3D coli(1.,0.,0.); Rigid2D testbody(mbs,x0i,rho,sizei,coli); int nr = mbs->AddElement(&testbody); //MBSLoad load; //load.SetForceVector2D(Vector2D(1e-4,2e-4),Vector2D(0.)); mbs->GetElement(nr).AddLoad(grav); TArray<Vector2D> points; int ni = 32; for(int j=0; j<=ni; ++j) points.Add(Vector2D( r0*cos(2*MY_PI/ni*j), r0*sin(2*MY_PI/ni*j) )); //for better visualization of rotation GeomLine2D c1(mbs,nr,Vector2D(0.,-0.5*r0),Vector2D(0.,0.5*r0),Vector3D(1.,0.,0.)); GeomLine2D c2(mbs,nr,Vector2D(-0.5*r0,0.),Vector2D(0.5*r0,0.),Vector3D(1.,0.,0.)); c1.SetDrawParam(Vector3D(2*wi, 10., 0.)); c2.SetDrawParam(Vector3D(2*wi, 10., 0.)); mbs->GetElement(nr).Add(c1); mbs->GetElement(nr).Add(c2); mbs->GetElement(nr).SetAltShape(1); //sensors //{ // FieldVariableElementSensor s1(mbs); // s1.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.)); // s1.SetSensorName(mystr("rigid")+mystr("_x")); // mbs->AddSensor(&s1); // FieldVariableElementSensor s2(mbs); // s2.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.)); // s2.SetSensorName(mystr("rigid")+mystr("_y")); // mbs->AddSensor(&s2); // FieldVariableElementSensor s3(mbs); // s3.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.)); // s3.SetSensorName(mystr("rigid")+mystr("_vx")); // mbs->AddSensor(&s3); // FieldVariableElementSensor s4(mbs); // s4.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.)); // s4.SetSensorName(mystr("rigid")+mystr("_vy")); // mbs->AddSensor(&s4); //} ////lock rotation //if(edc->TreeGetInt("Geometry.lock_rigid_body_rotation")) //{ // CoordConstraint cc1(mbs, nr, 3, cdim); // mbs->AddElement(&cc1); //} //contact bodyind = 2; for(int i=1; i<=points.Length(); ++i) { gc.AddSlaveNode(nr, points(i), cstiff, bodyind); } if(edc->TreeGetInt("Geometry.mutual_contact")) { for(int i=1; i<points.Length(); ++i) { gc.AddMasterSegment(nr,points(i),points(i+1),bodyind); //be careful with orientation of master segments GeomLine2D c1(mbs,nr,points(i),points(i+1),Vector3D(1.,0.,0.)); c1.SetDrawParam(Vector3D(2*wi, 10., 0.)); mbs->GetElement(nr).Add(c1); } } } //===============================frame========================================= points.Flush(); dx = box_x/nbox_x; dy = box_y/nbox_y; for(int i=0; i<nbox_x; ++i) points.Add(Vector2D(-0.5*box_x+i*dx,-0.5*box_y)); for(int i=0; i<nbox_y; ++i) points.Add(Vector2D(0.5*box_x,-0.5*box_y+i*dy)); for(int i=0; i<nbox_x; ++i) points.Add(Vector2D(0.5*box_x-i*dx,0.5*box_y)); for(int i=0; i<=nbox_y; ++i) points.Add(Vector2D(-0.5*box_x,0.5*box_y-i*dy)); //contact bodyind = 0; //must be 0 for mbs for(int i=1; i<points.Length(); ++i) { gc.AddMasterSegment(0,points(i+1),points(i), bodyind); //be careful with orientation of master segments GeomLine2D c1(mbs,0,points(i+1),points(i),Vector3D(0.,0.,0.)); c1.SetDrawParam(Vector3D(2*wi, 10., 0.)); mbs->Add(c1); } //finish contact gc.FinishContactDefinition(); mbs->AddElement(&gc); mbs->Assemble(); return 1; };
void UTIL_SendHudText(int client, const hud_text_parms &textparms, const char *pMessage) { cell_t players[1]; players[0] = client; #if SOURCE_ENGINE == SE_DOTA CUserMsg_HudMsg *msg = (CUserMsg_HudMsg *)g_UserMsgs.StartProtobufMessage(g_HudMsgNum, players, 1, 0); msg->set_channel(textparms.channel & 0xFF); msg->set_x(textparms.x); msg->set_y(textparms.y); Color c1(textparms.r1, textparms.g1, textparms.b1, textparms.a1); msg->set_color1(c1.GetRawColor()); Color c2(textparms.r2, textparms.g2, textparms.b2, textparms.a2); msg->set_color2(c2.GetRawColor()); msg->set_effect(textparms.effect); msg->set_fade_in_time(textparms.fadeinTime); msg->set_fade_out_time(textparms.fadeoutTime); msg->set_hold_time(textparms.holdTime); msg->set_fx_time(textparms.fxTime); msg->set_message(pMessage); #elif SOURCE_ENGINE == SE_CSGO CCSUsrMsg_HudMsg *msg = (CCSUsrMsg_HudMsg *)g_UserMsgs.StartProtobufMessage(g_HudMsgNum, players, 1, 0); msg->set_channel(textparms.channel & 0xFF); CMsgVector2D *pos = msg->mutable_pos(); pos->set_x(textparms.x); pos->set_y(textparms.y); CMsgRGBA *color1 = msg->mutable_clr1(); color1->set_r(textparms.r1); color1->set_g(textparms.g1); color1->set_b(textparms.b1); color1->set_a(textparms.a1); CMsgRGBA *color2 = msg->mutable_clr2(); color2->set_r(textparms.r2); color2->set_g(textparms.g2); color2->set_b(textparms.b2); color2->set_a(textparms.a2); msg->set_effect(textparms.effect); msg->set_fade_in_time(textparms.fadeinTime); msg->set_fade_out_time(textparms.fadeoutTime); msg->set_hold_time(textparms.holdTime); msg->set_fx_time(textparms.fxTime); msg->set_text(pMessage); #else bf_write *bf = g_UserMsgs.StartBitBufMessage(g_HudMsgNum, players, 1, 0); bf->WriteByte(textparms.channel & 0xFF ); bf->WriteFloat(textparms.x); bf->WriteFloat(textparms.y); bf->WriteByte(textparms.r1); bf->WriteByte(textparms.g1); bf->WriteByte(textparms.b1); bf->WriteByte(textparms.a1); bf->WriteByte(textparms.r2); bf->WriteByte(textparms.g2); bf->WriteByte(textparms.b2); bf->WriteByte(textparms.a2); bf->WriteByte(textparms.effect); bf->WriteFloat(textparms.fadeinTime); bf->WriteFloat(textparms.fadeoutTime); bf->WriteFloat(textparms.holdTime); bf->WriteFloat(textparms.fxTime); bf->WriteString(pMessage); #endif g_UserMsgs.EndMessage(); }
bool VStableSolve::isVStable() { Variable x1,x2,a1,a2;//,a; // double a=10; // double _ii[2][2]={{-10,-10},{-10,10}}; // IntervalVector a(2,_ii); Function f_sup("f_sup.txt"); Function f_inf("f_inf.txt"); Function V("V.txt"); Function dV("gradV.txt"); NumConstraint c1_c(x1,x2,a1,a2,a1*dV(x1,x2)[0]+a2*dV(x1,x2)[1]>=0); NumConstraint c21_c(x1,x2,a1,a2,f_sup(x1,x2)[0]-a1>=0); NumConstraint c22_c(x1,x2,a1,a2,f_sup(x1,x2)[1]-a2>=0); NumConstraint c31_c(x1,x2,a1,a2,a1-f_inf(x1,x2)[0]>=0); NumConstraint c32_c(x1,x2,a1,a2,a2-f_inf(x1,x2)[1]>=0); NumConstraint c41_c(x1,x2,V(x1,x2)>=0); NumConstraint c42_c(x1,x2,V(x1,x2)<=v_bar); CtcFwdBwd c1(c1_c); CtcFwdBwd c21(c21_c); CtcFwdBwd c22(c22_c); CtcCompo c2(c21,c22); CtcFwdBwd c31(c31_c); CtcFwdBwd c32(c32_c); CtcCompo c3(c31, c32); CtcFwdBwd c41(c41_c); CtcFwdBwd c42(c42_c); CtcCompo c4(c41,c42); CtcCompo cOut1(c1,c2); CtcCompo cOut2(c3,c4); CtcCompo cOut(cOut1,cOut2); // Build the initial box. IntervalVector box(4); box[0]=Interval(-10,10); box[1]=Interval(-10,10); box[2]=Interval::ALL_REALS; box[3]=Interval::ALL_REALS; // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. LargestFirst lf; stack<IntervalVector> s; s.push(box); while (!s.empty()) { // Get a copy of the current box (on top of the stack) IntervalVector box=s.top(); // qDebug() << "a[0]= [" <<box[2].lb() << "; " << box[2].ub() << "], a[1]= [" << box[3].lb() << "; " <<box[3].ub() << "]" << endl; // Remove the box from the stack s.pop(); try { // // Remove the part that is inside //// contract_and_draw(cOut,box,Qt::darkBlue,Qt::cyan); IntervalVector initbox=box; // get a copy try { // cOut.contract(box); // if (box==initbox) return; // nothing contracted. if(box!=initbox){ IntervalVector* rest; // int n=initbox.diff(box,rest); // calculate the set difference // for (int i=0; i<n; i++) { // display the boxes // frame.DrawBox(rest[i][0],rest[i][1],QPen(pencolor),QBrush(brushcolor)); // } // delete[] rest; } } catch(EmptyBoxException&) { // frame.DrawBox(initbox[0],initbox[1],QPen(pencolor),QBrush(brushcolor)); } // if (box.is_empty()) { continue; } // // Check if the box is small enough if (box.max_diam()<0.0001){//epsilon) { return false; // il y a une situation incertaine: on conclut non-V-Stable // frame.DrawBox(box[0],box[1],QPen(Qt::yellow),QBrush(Qt::yellow)); } else { // otherwise, bisect it and // push the two subboxes on the stack. pair<IntervalVector,IntervalVector> boxes=lf.bisect(box); s.push(boxes.first); s.push(boxes.second); } } catch(EmptyBoxException&) { } } return true; }
Sivia::Sivia(repere& R, struct sivia_struct *par) : R(R) { par->area = 0; // Create the function we want to apply SIVIA on. Variable x,y; double ei = par->ei; double xb=par->xb1,yb=par->yb1; Interval xbi=Interval(par->xb1-ei,par->xb1+ei),ybi=Interval(par->yb1-ei,par->yb1+ei); double arc = par->sonar_arc; double r = pow(par->sonar_radius,2); double th1 = par->th[0]; double th2=th1+arc; double th21= par->th[1]; double th22=th21 + arc; double th31= par->th[2]; double th32=th31 + arc; double e=1; double epsilon = par->epsilon; double xin,yin; // First SONAR Function f(x,y,sqr(x-xbi)+sqr(y-ybi)); NumConstraint c1(x,y,f(x,y)<=r+e); NumConstraint c2(x,y,f(x,y)>=e); NumConstraint c3(x,y,f(x,y)>r+e); NumConstraint c4(x,y,f(x,y)<e); double sign1,sign2; if(cos(th1)>0) sign1=1; else sign1=-1; if(cos(th2)<0) sign2=1; else sign2=-1; NumConstraint cth11(x,y,sign1*(y-ybi-((sin(th1))/(cos(th1)))*(x-xbi))<0); NumConstraint cth12(x,y,sign1*(y-ybi-((sin(th1))/(cos(th1)))*(x-xbi))>0); NumConstraint cth21(x,y,sign2*(y-ybi-((sin(th2))/(cos(th2)))*(x-xbi))<0); NumConstraint cth22(x,y,sign2*(y-ybi-((sin(th2))/(cos(th2)))*(x-xbi))>0); // Create contractors with respect to each // of the previous constraints. CtcFwdBwd out1(c1); CtcFwdBwd out2(c2); CtcFwdBwd in1(c3); CtcFwdBwd in2(c4); CtcFwdBwd outth1(cth12); CtcFwdBwd inth1(cth11); CtcFwdBwd inth2(cth21); CtcFwdBwd outth2(cth22); // CtcIn inside(f,Interval(-1,1)); // CtcNotIn outside(f,Interval(-1,1)); // Create a contractor that removes all the points // that do not satisfy either f(x,y)<=2 or f(x,y)>=0. // These points are "outside" of the solution set. CtcCompo outside1(out1,out2,outth1,outth2); // Create a contractor that removes all the points // that do not satisfy both f(x,y)>2 or f(x,y)<0. // These points are "inside" the solution set. CtcUnion inside11(in1,in2,inth1); CtcUnion inside1(inside11,inth2); // Second SONAR double xb2=par->xb2,yb2=par->yb2; Interval xb2i=Interval(par->xb2-ei,par->xb2+ei),yb2i=Interval(par->yb2-ei,par->yb2+ei); Function f2(x,y,sqr(x-xb2i)+sqr(y-yb2i)); NumConstraint c21(x,y,f2(x,y)<=r+e); NumConstraint c22(x,y,f2(x,y)>=e); NumConstraint c23(x,y,f2(x,y)>r+e); NumConstraint c24(x,y,f2(x,y)<e); double sign21,sign22; if(cos(th21)>0) sign21=-1; else sign21=1; if(cos(th22)<0) sign22=1; else sign22=-1; NumConstraint cth211(x,y,sign21*(y-yb2i-((sin(th21))/(cos(th21)))*(x-xb2i))<0); NumConstraint cth212(x,y,sign21*(y-yb2i-((sin(th21))/(cos(th21)))*(x-xb2i))>0); NumConstraint cth221(x,y,sign22*(y-yb2i-((sin(th22))/(cos(th22)))*(x-xb2i))<0); NumConstraint cth222(x,y,sign22*(y-yb2i-((sin(th22))/(cos(th22)))*(x-xb2i))>0); // Create contractors with respect to each // of the previous constraints. CtcFwdBwd out21(c21); CtcFwdBwd out22(c22); CtcFwdBwd in21(c23); CtcFwdBwd in22(c24); CtcFwdBwd outth21(cth211); CtcFwdBwd inth21(cth212); CtcFwdBwd inth22(cth221); CtcFwdBwd outth22(cth222); // CtcIn inside(f,Interval(-1,1)); // CtcNotIn outside(f,Interval(-1,1)); // Create a contractor that removes all the points // that do not satisfy either f(x,y)<=2 or f(x,y)>=0. // These points are "outside" of the solution set. CtcCompo outside2(out21,out22,outth21,outth22); // Create a contractor that removes all the points // that do not satisfy both f(x,y)>2 or f(x,y)<0. // These points are "inside" the solution set. CtcUnion inside21(in21,in22,inth21); CtcUnion inside2(inside21,inth22); //Third SONAR double xb3=par->xb3,yb3=par->yb3; Interval xb3i=Interval(par->xb3-ei,par->xb3+ei),yb3i=Interval(par->yb3-ei,par->yb3+ei); Function f3(x,y,sqr(x-xb3i)+sqr(y-yb3i)); NumConstraint c31(x,y,f3(x,y)<=r+e); NumConstraint c32(x,y,f3(x,y)>=e); NumConstraint c33(x,y,f3(x,y)>r+e); NumConstraint c34(x,y,f3(x,y)<e); double sign31,sign32; if(cos(th31)>0) sign31=-1; else sign31=1; if(cos(th32)<0) sign32=1; else sign32=-1; NumConstraint cth311(x,y,sign31*(y-yb3i-((sin(th31))/(cos(th31)))*(x-xb3i))<0); NumConstraint cth312(x,y,sign31*(y-yb3i-((sin(th31))/(cos(th31)))*(x-xb3i))>0); NumConstraint cth321(x,y,sign32*(y-yb3i-((sin(th32))/(cos(th32)))*(x-xb3i))<0); NumConstraint cth322(x,y,sign32*(y-yb3i-((sin(th32))/(cos(th32)))*(x-xb3i))>0); // Create contractors with respect to each // of the previous constraints. CtcFwdBwd out31(c31); CtcFwdBwd out32(c32); CtcFwdBwd in31(c33); CtcFwdBwd in32(c34); CtcFwdBwd outth31(cth311); CtcFwdBwd inth31(cth312); CtcFwdBwd inth32(cth321); CtcFwdBwd outth32(cth322); // CtcIn inside(f,Interval(-1,1)); // CtcNotIn outside(f,Interval(-1,1)); // Create a contractor that removes all the points // that do not satisfy either f(x,y)<=2 or f(x,y)>=0. // These points are "outside" of the solution set. CtcCompo outside3(out31,out32,outth31,outth32); // Create a contractor that removes all the points // that do not satisfy both f(x,y)>2 or f(x,y)<0. // These points are "inside" the solution set. CtcUnion inside31(in31,in32,inth31); CtcUnion inside3(inside31,inth32); //CtcQInter inter(inside,1); //Artifact MODELISATION double xa = par->xa; double ya = par->ya; double ra = par->ra; Function f_a(x,y,sqr(x-xa)+sqr(y-ya)); NumConstraint ca1(x,y,f_a(x,y)<=sqr(ra)); NumConstraint ca2(x,y,f_a(x,y)>=sqr(ra)-par->thick); NumConstraint ca3(x,y,f_a(x,y)>sqr(ra)); NumConstraint ca4(x,y,f_a(x,y)<sqr(ra)-par->thick); CtcFwdBwd aout1(ca1); CtcFwdBwd aout2(ca2); CtcFwdBwd ain1(ca3); CtcFwdBwd ain2(ca4); CtcUnion ain(ain1,ain2); CtcCompo aout(aout1,aout2); //Robot MODELISATION double xr = par->xr; //robot position x double yr = par->yr; //robot position y double wr = par->wr; //robot width double lr = par->lr; //robot length double ep = par->thick; xr = par->xr - wr/2; NumConstraint inrx1(x,y,x>xr+ep); NumConstraint outrx1(x,y,x<xr+ep); NumConstraint inrx2(x,y,x<xr-ep); NumConstraint outrx2(x,y,x>xr-ep); NumConstraint inry1(x,y,y<yr-lr/2); NumConstraint outry1(x,y,y>yr-lr/2); NumConstraint inry2(x,y,y>yr+lr/2); NumConstraint outry2(x,y,y<yr+lr/2); CtcFwdBwd incrx1(inrx1); CtcFwdBwd incrx2(inrx2); CtcFwdBwd incry1(inry1); CtcFwdBwd incry2(inry2); CtcFwdBwd outcrx1(outrx1); CtcFwdBwd outcrx2(outrx2); CtcFwdBwd outcry1(outry1); CtcFwdBwd outcry2(outry2); CtcUnion inrtemp(incrx1,incrx2,incry1); CtcUnion inr1(inrtemp,incry2); CtcCompo outrtemp(outcrx1,outcrx2,outcry1); CtcCompo outr1(outrtemp,outcry2); //2nd rectangle xr = par->xr + wr/2; NumConstraint inrx21(x,y,x>xr+ep); NumConstraint outrx21(x,y,x<xr+ep); NumConstraint inrx22(x,y,x<xr-ep); NumConstraint outrx22(x,y,x>xr-ep); NumConstraint inry21(x,y,y<yr-lr/2); NumConstraint outry21(x,y,y>yr-lr/2); NumConstraint inry22(x,y,y>yr+lr/2); NumConstraint outry22(x,y,y<yr+lr/2); CtcFwdBwd incrx21(inrx21); CtcFwdBwd incrx22(inrx22); CtcFwdBwd incry21(inry21); CtcFwdBwd incry22(inry22); CtcFwdBwd outcrx21(outrx21); CtcFwdBwd outcrx22(outrx22); CtcFwdBwd outcry21(outry21); CtcFwdBwd outcry22(outry22); CtcUnion inrtemp2(incrx21,incrx22,incry21); CtcUnion inr2(inrtemp2,incry22); CtcCompo outrtemp2(outcrx21,outcrx22,outcry21); CtcCompo outr2(outrtemp2,outcry22); //3nd rectangle top rectangle yr=par->yr+par->lr/2; xr=par->xr; NumConstraint inrx31(x,y,x>xr+wr/2+ep); NumConstraint outrx31(x,y,x<xr+wr/2+ep); NumConstraint inrx32(x,y,x<xr-wr/2-ep); NumConstraint outrx32(x,y,x>xr-wr/2-ep); NumConstraint inry31(x,y,y<yr-ep); NumConstraint outry31(x,y,y>yr-ep); NumConstraint inry32(x,y,y>yr+ep); NumConstraint outry32(x,y,y<yr+ep); CtcFwdBwd incrx31(inrx31); CtcFwdBwd incrx32(inrx32); CtcFwdBwd incry31(inry31); CtcFwdBwd incry32(inry32); CtcFwdBwd outcrx31(outrx31); CtcFwdBwd outcrx32(outrx32); CtcFwdBwd outcry31(outry31); CtcFwdBwd outcry32(outry32); CtcUnion inrtemp3(incrx31,incrx32,incry31); CtcUnion inr3(inrtemp3,incry32); CtcCompo outrtemp3(outcrx31,outcrx32,outcry31); CtcCompo outr3(outrtemp3,outcry32); //4 rectangle bot yr=par->yr-par->lr/2; xr=par->xr; NumConstraint inrx41(x,y,x>xr+wr/2+ep); NumConstraint outrx41(x,y,x<xr+wr/2+ep); NumConstraint inrx42(x,y,x<xr-wr/2-ep); NumConstraint outrx42(x,y,x>xr-wr/2-ep); NumConstraint inry41(x,y,y<yr-ep); NumConstraint outry41(x,y,y>yr-ep); NumConstraint inry42(x,y,y>yr+ep); NumConstraint outry42(x,y,y<yr+ep); CtcFwdBwd incrx41(inrx41); CtcFwdBwd incrx42(inrx42); CtcFwdBwd incry41(inry41); CtcFwdBwd incry42(inry42); CtcFwdBwd outcrx41(outrx41); CtcFwdBwd outcrx42(outrx42); CtcFwdBwd outcry41(outry41); CtcFwdBwd outcry42(outry42); CtcUnion inrtemp4(incrx41,incrx42,incry41); CtcUnion inr4(inrtemp4,incry42); CtcCompo outrtemp4(outcrx41,outcrx42,outcry41); CtcCompo outr4(outrtemp4,outcry42); CtcCompo inrtp(inr1,inr2,inr3); CtcUnion outrtp(outr1,outr2,outr3); CtcCompo inr(inrtp,inr4); CtcUnion outr(outrtp,outr4); yr = par->yr; int maxq = 3; //nb of contractors int Qinter = 2; int ctcq = maxq - Qinter + 1; //nb for q-relaxed function of Ibex Array<Ctc> inside1r1(inside1,inr,ain); Array<Ctc> outside1r1(outside1,outr,aout); Array<Ctc> inside2r1(inside2,inr,ain); Array<Ctc> outside2r1(outside2,outr,aout); Array<Ctc> inside3r1(inside3,inr,ain); Array<Ctc> outside3r1(outside3,outr,aout); CtcQInter outside1r(outside1r1,Qinter); CtcQInter inside1r(inside1r1,ctcq); CtcQInter outside2r(outside2r1,Qinter); CtcQInter inside2r(inside2r1,ctcq); CtcQInter outside3r(outside3r1,Qinter); CtcQInter inside3r(inside3r1,ctcq); // Build the initial box. IntervalVector box(2); box[0]=Interval(-10,10); box[1]=Interval(-10,10); par->vin.clear(); // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. int nbox1=0; LargestFirst lf; IntervalVector viinside1(2); stack<IntervalVector> s; s.push(box); while (!s.empty()) { IntervalVector box=s.top(); s.pop(); contract_and_draw(inside1r,box,viinside1,1,par,nbox1,Qt::magenta,Qt::red); if (box.is_empty()) { continue; } contract_and_draw(outside1r,box,viinside1,0,par,nbox1,Qt::darkBlue,Qt::cyan); if (box.is_empty()) { continue; } if (box.max_diam()<epsilon) { R.DrawBox(box[0].lb(),box[0].ub(),box[1].lb(),box[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush)); } else { pair<IntervalVector,IntervalVector> boxes=lf.bisect(box); s.push(boxes.first); s.push(boxes.second); } } if(par->isinside==1){ robot_position_estimator(nbox1,par); par->isinside1=1; par->isinside=0; //cout<<"area1: "<<par->area<<endl; } IntervalVector box2(2); box2[0]=Interval(-10,10); box2[1]=Interval(-10,10); // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. int nbox2=0; LargestFirst lf2; IntervalVector viinside2(2); stack<IntervalVector> s2; s2.push(box2); while (!s2.empty()) { IntervalVector box2=s2.top(); s2.pop(); contract_and_draw(inside2r,box2,viinside2,2,par,nbox2,Qt::magenta,Qt::red); if (box2.is_empty()) { continue; } contract_and_draw(outside2r,box2,viinside2,0,par,nbox2,Qt::darkBlue,Qt::cyan); if (box2.is_empty()) { continue; } if (box2.max_diam()<epsilon) { R.DrawBox(box2[0].lb(),box2[0].ub(),box2[1].lb(),box2[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush)); } else { pair<IntervalVector,IntervalVector> boxes2=lf2.bisect(box2); s2.push(boxes2.first); s2.push(boxes2.second); } } if(par->isinside==1){ robot_position_estimator(nbox2,par); par->isinside2=1; par->isinside=0; //cout<<"area2: "<<par->area<<endl; } IntervalVector box3(2); box3[0]=Interval(-10,10); box3[1]=Interval(-10,10); // Build the way boxes will be bisected. // "LargestFirst" means that the dimension bisected // is always the largest one. int nbox3=0; LargestFirst lf3; IntervalVector viinside3(2); stack<IntervalVector> s3; s3.push(box3); while (!s3.empty()) { IntervalVector box3=s3.top(); s3.pop(); contract_and_draw(inside3r,box3,viinside3,3,par,nbox3,Qt::magenta,Qt::red); if (box3.is_empty()) { continue; } contract_and_draw(outside3r,box3,viinside3,0,par,nbox3,Qt::darkBlue,Qt::cyan); if (box3.is_empty()) { continue; } if (box3.max_diam()<epsilon) { R.DrawBox(box3[0].lb(),box3[0].ub(),box3[1].lb(),box3[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush)); } else { pair<IntervalVector,IntervalVector> boxes3=lf3.bisect(box3); s3.push(boxes3.first); s3.push(boxes3.second); } } if(par->isinside==1){ robot_position_estimator(nbox3,par); par->isinside3=1; par->isinside=0; //cout<<"area3: "<<par->area<<endl; } par->state.clear(); if (par->isinside1 ==1 || par->isinside2 ==1 || par->isinside3 ==1){ double *aimth = new double[3]; aimth[0] = get_angle(xb,yb,par->xin,par->yin)+M_PI ; aimth[1] = get_angle(xb2,yb2,par->xin,par->yin)+M_PI; aimth[2] = get_angle(xb3,yb3,par->xin,par->yin)+M_PI; R.DrawLine(xb,yb,xb+r*cos(aimth[0]),yb+r*sin(aimth[0]),QPen(Qt::red)); R.DrawLine(xb2,yb2,xb2+r*cos(aimth[1]),yb2+r*sin(aimth[1]),QPen(Qt::red)); R.DrawLine(xb3,yb3,xb3+r*cos(aimth[2]),yb3+r*sin(aimth[2]),QPen(Qt::red)); par->state = std::string("found"); double kp = par->kp; double u[3]; for (int i=0;i<3;i++){ u[i] = -kp*atan(tan((par->th[i] - (aimth[i] - arc/2.0 ))/2)); if(u[i]>par->sonar_speed) par->th[i] += par->sonar_speed; if(u[i]<-par->sonar_speed) par->th[i] += -par->sonar_speed; else par->th[i] += u[i]; } // for (int i=0;i<3;i++){ // u[i] = atan(tan((par->th[i] - (aimth[i] - arc/2.0 ))/2)); // par->th[i] -=u[i]; // } } r = sqrt(r); //cout<<"th1"<<th1<<endl; R.DrawEllipse(xb,yb,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawEllipse(xb2,yb2,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawEllipse(xb3,yb3,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawLine(xb,yb,xb+r*cos(th2),yb+r*sin(th2),QPen(Qt::green)); R.DrawLine(xb2,yb2,xb2+r*cos(th22),yb2+r*sin(th22),QPen(Qt::green)); R.DrawLine(xb3,yb3,xb3+r*cos(th32),yb3+r*sin(th32),QPen(Qt::green)); R.DrawLine(xb,yb,xb+r*cos(th1),yb+r*sin(th1),QPen(Qt::green)); R.DrawLine(xb2,yb2,xb2+r*cos(th21),yb2+r*sin(th21),QPen(Qt::green)); R.DrawLine(xb3,yb3,xb3+r*cos(th31),yb3+r*sin(th31),QPen(Qt::green)); R.DrawEllipse(par->xa,par->ya,par->ra,QPen(Qt::black),QBrush(Qt::NoBrush)); R.DrawRobot(xr-wr/2,yr+lr/2,-3.14/2,wr,lr); R.Save("paving"); par->vin.clear(); }
void test_basic_template( ForwardIterator first,ForwardIterator last BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Flyweight)) { typedef typename Flyweight::value_type value_type; ForwardIterator it; for(it=first;it!=last;++it){ /* construct/copy/destroy */ Flyweight f1(*it); Flyweight f2; Flyweight c1(f1); Flyweight c2(static_cast<const Flyweight&>(f2)); value_type v1(*it); boost::value_initialized<value_type> v2; BOOST_TEST(f1.get_key()==*it); BOOST_TEST((f1==f2)==(f1.get()==v2.data())); BOOST_TEST(f1==c1); BOOST_TEST(f2==c2); f1=f1; BOOST_TEST(f1==f1); c1=f2; BOOST_TEST(c1==f2); c1=f1; BOOST_TEST(c1==f1); /* convertibility to underlying type */ BOOST_TEST(f1.get()==v1); /* identity of reference */ BOOST_TEST(&f1.get()==&c1.get()); /* modifiers */ f1.swap(f1); BOOST_TEST(f1==c1); f1.swap(f2); BOOST_TEST(f1==c2); BOOST_TEST(f2==c1); boost::flyweights::swap(f1,f2); BOOST_TEST(f1==c1); BOOST_TEST(f2==c2); /* specialized algorithms */ std::ostringstream oss1; oss1<<f1; std::ostringstream oss2; oss2<<f1.get(); BOOST_TEST(oss1.str()==oss2.str()); } }