Example #1
0
	void Op_GE_001( )
	{
		quaternion_type q1( 2, 3, 3, 4 );
		quaternion_type q2( 1, 2, 3, 4 );

		CPPUNIT_ASSERTION( q1 > q2 );
	}
Example #2
0
	void Op_LE_004( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( 1, 2, 4, 4 );

		CPPUNIT_ASSERTION( q1 <= q2 );
	}
Example #3
0
	void Op_GT_004( )
	{
		quaternion_type q1( 1, 2, 3, 5 );
		quaternion_type q2( 1, 2, 3, 4 );

		CPPUNIT_ASSERTION( q1 > q2 );
	}
void Test() {
  std::string str('x', 4);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are probably swapped [misc-string-constructor]
  std::wstring wstr(L'x', 4);
  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are probably swapped
  std::string s0(0, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
  std::string s1(-4, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
  std::string s2(0x1000000, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
  
  std::string q0("test", 0);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
  std::string q1(kText, -4);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
  std::string q2("test", 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q3(kText, 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q4(kText2, 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q5(kText3,  0x1000000);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
}
Example #5
0
	void Op_LT_003( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( 1, 2, 4, 4 );

		CPPUNIT_ASSERTION( q1 < q2 );
	}
Example #6
0
//only for x^2 - 2y^2= -1;
void max_dig_pell(int num, vector<int>& vroot, vector<I64Pair>& results)
{
    results.clear();
    i64 p0(vroot[0]);
    i64 q0(1);
    i64 p1(vroot[0]*vroot[1]+1);
    i64 q1(vroot[1]);
    i64 p2(1);
    i64 q2(1);
    results.push_back(I64Pair(p0,q0));

    vroot.erase(vroot.begin());
    int vsize = vroot.size();
    //int r = vsize - 1;
    int start = 2;
    for(int s = start; true; ++s){
        int idx = (s-1)%vsize;
        int value = vroot[idx];
        p2 = p1*(value) + p0;
        q2 = q1*(value) + q0;
        p0 = p1; q0 = q1; 
        p1 = p2; q1 = q2;
        if(p2 > 1e18) break;
        if((s)%(2) == 0) {
            assert(p1*p1-5*q1*q1==-1);
            results.push_back(I64Pair(p1, q1));
        }
    }
}
Example #7
0
int main() {

    queue<int> q; 
    q.push(10);

    std::cout << q << std::endl;

    

    std::vector<int> vec(5, 1);

    queue<int> q3(vec.begin(), vec.end());
    std::cout << q3 << std::endl;

    int a[] = {1, 2, 3, 4, 5};
    queue<int> q2(a, a+5);

    std::cout << q2 << std::endl;

    queue<int> q4; 
    q4 = q3; 

    std::cout << q4 << std::endl;

    return 0;
}
Example #8
0
vector<double> CIEColor::SinglehueSequential(double t, double s, double b, double c, double h)
{
	int N=10;
	vector<double> Pseg;
	vector<double> p0(3,0),p1(3,0), p2(3,0), q0(3,0), q1(3,0), q2(3,0);
		
	p2[0]=100, p2[1]=0, p2[2]=h;
	p1=dividingLCHuvforMSC_H(0,100,h);
	p0[0]=0, p0[1]=0, p0[2]=h;

	q0[0] = (1-s) * p0[0] + s *p1[0];
	q0[1] = (1-s) * p0[1] + s *p1[1];
	q0[2] = (1-s) * p0[2] + s *p1[2];

	q2[0] = (1-s) * p2[0] + s *p1[0];
	q2[1] = (1-s) * p2[1] + s *p1[1];
	q2[2] = (1-s) * p2[2] + s *p1[2];

	q1[0] = (q0[0] + q2[0])/2;
	q1[1] = (q0[1] + q2[1])/2;
	q1[2] = (q0[2] + q2[2])/2;

	vector<double> T = getT(p0, p1, p2, q0, q1, q2, 125-125*pow(0.2,(1-c)*b+t*c)); 
	Pseg = getCseg(p0, p1, p2, q0, q1, q2, T[0]);
	Pseg[2]=h;
	double r, g, k;
	//LCHuvtoRGB(Pseg[0], Pseg[1], Pseg[2], r, g, k);
	closestLCHuvtoRGB(Pseg[0], Pseg[1], Pseg[2], r, g, k);
	Pseg[0]= r, Pseg[1]=g, Pseg[2]=k;
	return Pseg;
}
Example #9
0
	void Op_GE_005( )
	{
		quaternion_type q1( 1, 2, 3, 5 );
		quaternion_type q2( 1, 2, 3, 4 );

		CPPUNIT_ASSERTION( q1 >= q2 );
	}
Example #10
0
    bool AlphaFinder::finalPart(Real alphaFound,
                                Integer stepindex,
                                const std::vector<Volatility>& ratetwohomogeneousvols,
                                Real quadraticPart,
                                Real linearPart,
                                Real constantPart,
                                Real& alpha,
                                Real& a,
                                Real& b,
                                std::vector<Volatility>& ratetwovols) {
            alpha = alphaFound;
            quadratic q2(quadraticPart, linearPart, constantPart-targetVariance_ );
            parametricform_->setAlpha(alpha);
            Real y; // dummy
            q2.roots(a,y);

            Real varSoFar=0.0;
            for (Integer i =0; i < stepindex+1; ++i) {
                ratetwovols[i] = ratetwohomogeneousvols[i] *
                                            (*parametricform_)(i) * a;
                varSoFar += ratetwovols[i]* ratetwovols[i];
            }

            Real VarToFind = totalVar_-varSoFar;
            if (VarToFind < 0)
                return false;
            Real requiredSd = std::sqrt(VarToFind);
            b = requiredSd / (ratetwohomogeneousvols[stepindex+1] *
                                            (*parametricform_)(stepindex));
            ratetwovols[stepindex+1] = requiredSd;
            return true;
    }
Example #11
0
File: main.cpp Project: netp/Queue
int main (int argc, char * const argv[]) {

    Queue<int> q1;
    q1.insere( 13 );
    q1.insere( 15 );
    q1.insere( 12 );
    q1.insere( 38 );
    q1.insere( 98 );

    Queue<int> q2( q1 );

    int x;

    std::cout << q1
        << std::endl
        << q2
        << std::endl
        << "o primeiro elemento da fila 2 é: "
        << q2.frente()
        << std::endl
        << "o último elemento da fila 2 é: "
        << q2.ultimo()
        << std::endl
    ;
    q2.retira( x );
    std::cout << "Retirando o elemento " 
        << x
        << " da fila. Esta fica com o elementos: "
        << std::endl
        << q2
    ;

    return 0;
}
Example #12
0
main(int argc, char *argv[]) {
    node gnd;
    node n1("n1");
    node n2("n2");
    node n3("n3");
    node n4("n4");
    node n5("n5");
    node n6("n6");

    vdc vcc("vcc", n6, gnd, 5.0);
    vpulse vin("vin", n1, gnd, 0, 5, 2e-9, 2e-9, 2e-9, 10e-9);
    r rb1("rb1", n1, n2, 10e3);
    r rc1("rc1", n6, n3, 1e3);
    qnd q1("q1", n3, n2, gnd);
    r rb2("rb2", n3, n4, 10e3);
    qnd q2("q2", n5, n4, gnd);
    r rc2("rc2", n6, n5, 1e3);

    op::monitor = 1;
    op();

    plot::output = *argv;
    plot::add("n1", "n3", "n5");

    tran::tsmin = 1.0e-30;
    tran::monitor = 1;
    tran(0.2e-9, 20.0e-9);
}
Example #13
0
Num seed_Ss(Num N, Num M, Num X, Num T, Num b, Num v)
{
  Num q2u = q2(N, M, 1.0);
  Num su = X / (1 - 1 / q2u);
  Num h2 = -(b * T + 2 * v * sqrt(T)) * X / (su - X);
  return X + (su - X) * (1 - exp(h2));
}
float poseEstimation::orientationDistance(cluster & c1, const cluster & c2)
{

	float _distance;

	// Compute distance between rotations
	_distance=(c1.meanPose.transform.rotation.w() * c2.meanPose.transform.rotation.w()) + 
		  	  (c1.meanPose.transform.rotation.x() * c2.meanPose.transform.rotation.x()) +
		  	  (c1.meanPose.transform.rotation.y() * c2.meanPose.transform.rotation.y()) +
		  	  (c1.meanPose.transform.rotation.z() * c2.meanPose.transform.rotation.z());


	if(_distance< (-pointPair::angleStepCos) )
	{
		//std::cout << "before change: " << 2*acos(_distance)*RAD_TO_DEG << std::endl;
		// Compute distance between rotations
		Eigen::Quaternion<float> q2(-c1.meanPose.transform.rotation.w(),-c1.meanPose.transform.rotation.x(),-c1.meanPose.transform.rotation.y(),-c2.meanPose.transform.rotation.z());

		c1.meanPose.transform.rotation=q2;

		_distance=(c1.meanPose.transform.rotation.w() * c2.meanPose.transform.rotation.w()) + 
			  	  (c1.meanPose.transform.rotation.x() * c2.meanPose.transform.rotation.x()) +
			  	  (c1.meanPose.transform.rotation.y() * c2.meanPose.transform.rotation.y()) +
			  	  (c1.meanPose.transform.rotation.z() * c2.meanPose.transform.rotation.z());

		//std::cout << "after change: " << 2*acos(_distance)*RAD_TO_DEG <<  std::endl;
	}

	if(_distance >= 1.0000000000)
	{
		_distance=1.00000000;
	//	std::cout << "UPS" << std::endl;	
	}
	return _distance; 
}
Example #15
0
int main() {
	//test ints
	Deque<int> deq;
	Queue<int> q(&deq);
	q.add(1);
	q.add(2);

	//Swap implementation
	List<int> lst;
	lst.push_back(3);
	q.changeImpl(&lst);
	q.add(4);
	q.add(5);
	displayAndEmptyQueue(q);

	//Test strings
	Deque<string> deq2;
	Queue<string> q2(&deq2);
	q2.add("1");
	q2.add("2");

	//Swap Implementation
	List<string> lst2;
	lst2.push_back("3");
	q2.changeImpl(&lst2);
	q2.add("4");
	q2.add("5");
	displayAndEmptyQueue(q2);
}
Example #16
0
TEST(Bullet, QuaternionTimesEqual)
{
  btQuaternion q1 (btVector3(1,0,0), M_PI/2.0);
  btQuaternion q2 (btVector3(0,0,1), M_PI/2.0);

  btQuaternion q3 (q1);
  q3*=q2;
  printf("(%f,%f,%f,%f)*(%f,%f,%f,%f)=(%f,%f,%f,%f)\n",q1.x(), q1.y(), q1.z(), q1.getAngle(), q2.x(), q2.y(), q2.z(), q2.getAngle(), q3.x(), q3.y(), q3.z(), q3.getAngle());

  btMatrix3x3 m3(q3);

  btVector3 xout = m3*btVector3(1,0,0);
  btVector3 yout = m3*btVector3(0,1,0);
  btVector3 zout = m3*btVector3(0,0,1);
  printf("(%f, %f, %f), (%f, %f, %f), (%f, %f, %f)\n", 
         xout.x(), xout.y(), xout.z() ,
         yout.x(), yout.y(), yout.z() ,
         zout.x(), zout.y(), zout.z());
  q3 = q1;
  q3*=q1;
  printf("(%f,%f,%f,%f)*(%f,%f,%f,%f)=(%f,%f,%f,%f)\n",q2.x(), q2.y(), q2.z(), q2.getAngle(), q1.x(), q1.y(), q1.z(), q1.getAngle(), q3.x(), q3.y(), q3.z(), q3.getAngle());

  m3.setRotation(q3);

  xout = m3*btVector3(1,0,0);
  yout = m3*btVector3(0,1,0);
  zout = m3*btVector3(0,0,1);
  printf("(%f, %f, %f), (%f, %f, %f), (%f, %f, %f)\n", 
         xout.x(), xout.y(), xout.z() ,
         yout.x(), yout.y(), yout.z() ,
         zout.x(), zout.y(), zout.z());
}
void main() {
  QuickFind q1(10);
  q1.Connect(3, 7);
  q1.Connect(6, 7);
  q1.Connect(0, 9);
  q1.Connect(2, 4);
  q1.Connect(8, 7);
  q1.Connect(6, 5);
  q1.PrintArray();

  QuickUnion q2(10);
  q2.Connect(1, 7);
  q2.Connect(6, 0);
  q2.Connect(2, 8);
  q2.Connect(2, 3);
  q2.Connect(7, 6);
  q2.Connect(3, 5);
  q2.Connect(9, 4);
  q2.Connect(9, 8);
  q2.Connect(8, 6);
  q2.PrintArray();

  QuickUnion q3(10);
  q3.Connect(9, 8);
  q3.Connect(9, 7);
  q3.Connect(9, 2);
  q3.Connect(4, 0);
  q3.Connect(4, 9);
  q3.Connect(1, 5);
  q3.Connect(3, 6);
  q3.Connect(3, 1);
  q3.Connect(9, 3);
  q3.PrintArray();
}
Example #18
0
int main()
{
    test<int> q(make<C>(5), test_allocator<int>(4));
    test<int> q2(q, test_allocator<int>(5));
    assert(q2.get_allocator() == test_allocator<int>(5));
    assert(q2.size() == 5);
}
 vector<int> findMinHeightTrees(int n, vector<pair<int, int>>& edges) {
     vector<int> ans;
     if(!n)
         return ans;
     if(n == 1){
         ans.push_back(0);
         return ans;
     }
     vector<int> deg(n);
     for(int i = 0; i < edges.size(); ++ i){
         ++ deg[edges[i].first];
         ++ deg[edges[i].second];
     }
     vector<unordered_set<int>> mp(n);
     for(int i = 0; i < edges.size(); ++ i){
         mp[edges[i].first].insert(edges[i].second);
         mp[edges[i].second].insert(edges[i].first);
     }
     vector<int> q1(n), q2(n);
     int front1 = 0, rear1 = 0, rear2 = 0, num = n;
     for(int i = 0; i < n; ++ i){
         if(deg[i] == 1){
             q1[rear1 ++] = i;
             -- deg[i];
         }
     }
     
     if(n == 2){
         for(int i = 0; i < n; ++ i)
             ans.push_back(i);
     }else{
         while(front1 < rear1){
             rear2 = 0;
             while(front1 < rear1){
                 int cur = q1[front1 ++];
                 unordered_set<int>::iterator it = mp[cur].begin();
                 -- num;
                 for(; it != mp[cur].end(); ++ it){
                     -- deg[*it];
                     if(deg[*it] == 1){
                         q2[rear2 ++] = *it;
                     }
                 }
             }
             
             for(int i = 0; i < rear2; ++ i)
                 q1[rear1 ++] = q2[i];
                 
             if(num <= 2)
                 break;
         }
         
         ans.resize(rear1 - front1);
         ans[0] = q1[front1];
         if(rear1 - front1 == 2)
             ans[1] = q1[front1 + 1];
     }
     
     return ans;
 }
Example #20
0
File: test1.c Project: jkkm/latrace
int main(void)
{
	static const struct st3 a = {1, 2, 3, 4, 5, 6};

	l1(100);
	l2(100, 200);
	l3(100, 200, 300);
	l4(100, 200, 300, 400);
	l5(100, 200, 300, 400, 500);
	l6(100, 200, 300, 400, 500, 600);
	l7(100, 200, 300, 400, 500, 600, 700);
	l8(100, 200, 300, 400, 500, 600, 700, 800);

	d1();
	d2(43);
	d3(100, 200);
	d4(a);
	d5('a', 43, a);
	d6('a', 1);

	c1(44);
	c2(100, 'a', 3.4);
	c3(200, 2.777, 'q');
	c4(200, 1);
	c5(1.1, 2.2);
	c6(1.23, 45.6);
	c7('z', 0x200);

	a1('a');
	a2(10);
	a3(20);
	a4(102030405060LL);

	b1('a', 20);
	b2(30, 'b');
	b3(10, 20, 30, 40, 50, 60);

	s1(sx);
	s1p(&sx);
	s2(sy);
	s3(sz);
	s4(sq);
	s5(sa);
	s6(sb);

	r1();
	r3();
	r4();

	q1(200, sx);
	q2(300, 't', sx);
	q3(400, 410, sy);
	q4(500, 510, sq);
	q5(600, 610, 'z', 'q', sq);

	real1("fresh air");
	real2();

	return 0;
}
Example #21
0
void tst_QQuaternion::multiply()
{
    QFETCH(float, x1);
    QFETCH(float, y1);
    QFETCH(float, z1);
    QFETCH(float, w1);
    QFETCH(float, x2);
    QFETCH(float, y2);
    QFETCH(float, z2);
    QFETCH(float, w2);

    QQuaternion q1(w1, x1, y1, z1);
    QQuaternion q2(w2, x2, y2, z2);

    // Use the simple algorithm at:
    // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q53
    // to calculate the answer we expect to get.
    QVector3D v1(x1, y1, z1);
    QVector3D v2(x2, y2, z2);
    float scalar = w1 * w2 - QVector3D::dotProduct(v1, v2);
    QVector3D vector = w1 * v2 + w2 * v1 + QVector3D::crossProduct(v1, v2);
    QQuaternion result(scalar, vector);

    QVERIFY((q1 * q2) == result);
}
   void AxisAngleClassTest::testAxisAngleClassTestCreation()
   {
      // test that it initializes to the identity
      gmtl::AxisAnglef q;
      CPPUNIT_ASSERT( q[0] == 0.0f );
      CPPUNIT_ASSERT( q[1] == 1.0f );
      CPPUNIT_ASSERT( q[2] == 0.0f );
      CPPUNIT_ASSERT( q[3] == 0.0f );

      // try out set...
      q.set( 1.0f, 2.0f, 3.0f, 902 );
      CPPUNIT_ASSERT( q[0] == 1.0f );
      CPPUNIT_ASSERT( q[1] == 2.0f );
      CPPUNIT_ASSERT( q[2] == 3.0f );
      CPPUNIT_ASSERT( q[3] == 902 );

      // try out setting with brackets
      q[0] = 5.0f;
      q[1] = 6.0f;
      q[2] = 7.0f;
      q[3] = 901;
      CPPUNIT_ASSERT( q[0] == 5.0f );
      CPPUNIT_ASSERT( q[1] == 6.0f );
      CPPUNIT_ASSERT( q[2] == 7.0f );
      CPPUNIT_ASSERT( q[3] == 901 );
     
      // try out element constructor
      gmtl::AxisAnglef q2( 10.0f, 11.0f, 12.0f, 902 );
      CPPUNIT_ASSERT( q2[0] == 10.0f );
      CPPUNIT_ASSERT( q2[1] == 11.0f );
      CPPUNIT_ASSERT( q2[2] == 12.0f );
      CPPUNIT_ASSERT( q2[3] == 902 );

      // try out copy constructor
      gmtl::AxisAnglef q3( q );
      CPPUNIT_ASSERT( q3[0] == 5.0f );
      CPPUNIT_ASSERT( q3[1] == 6.0f );
      CPPUNIT_ASSERT( q3[2] == 7.0f );
      CPPUNIT_ASSERT( q3[3] == 901 );

      // try out operator=() function
      gmtl::AxisAnglef q4;
      CPPUNIT_ASSERT( q4[0] == 0.0f );
      CPPUNIT_ASSERT( q4[1] == 1.0f );
      CPPUNIT_ASSERT( q4[2] == 0.0f );
      CPPUNIT_ASSERT( q4[3] == 0.0f );
      q4 = q2;
      CPPUNIT_ASSERT( q4[0] == 10.0f );
      CPPUNIT_ASSERT( q4[1] == 11.0f );
      CPPUNIT_ASSERT( q4[2] == 12.0f );
      CPPUNIT_ASSERT( q4[3] == 902 );

      // check out the const identities...
      gmtl::AxisAnglef q9( gmtl::AXISANGLE_IDENTITYF );
      CPPUNIT_ASSERT( q9[0] == 0.0f );
      CPPUNIT_ASSERT( q9[1] == 1.0f );
      CPPUNIT_ASSERT( q9[2] == 0.0f );
      CPPUNIT_ASSERT( q9[3] == 0.0f );
   }
Example #23
0
	void Op_Multiply_004( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( -2, -4, -6, -8 );
		quaternion_type q3 = -2 * q1;

		CPPUNIT_ASSERTION_EQUAL( q2, q3 );
	}
Example #24
0
	void Unit_003( )
	{
		quaternion_type q1( 0, 0, 0, 0 );
		quaternion_type q2( 0, 0, 0, 0 );

		CPPUNIT_ASSERTION_NO_THROW( q1.unit( ) );
		CPPUNIT_ASSERTION_EQUAL( q1.unit( ), q2 );
	}
Example #25
0
	void Unit_002( )
	{
		value_type len = static_cast< value_type >( 0.5 );
		quaternion_type q1( -1, -1, -1, -1 );
		quaternion_type q2( -len, -len, -len, -len );

		CPPUNIT_ASSERTION_EQUAL( q1.unit( ), q2 );
	}
Example #26
0
	void Inner_003( )
	{
		quaternion_type q1( 0, 1, 0, 1 );
		quaternion_type q2( 1, 0, 1, 0 );
		value_type s = q1.inner( q2 );

		CPPUNIT_ASSERTION_EQUAL( s, value_type( 0 ) );
	}
Example #27
0
	void Op_Divide_002( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( value_type( -0.5 ), -1, value_type( -1.5 ), -2 );
		quaternion_type q3 = q1 / value_type( -2 );

		CPPUNIT_ASSERTION_EQUAL( q2, q3 );
	}
Example #28
0
	void Op_Divide_001( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( value_type( 0.5 ), 1, value_type( 1.5 ), 2 );
		quaternion_type q3 = q1 / value_type( 2 );

		CPPUNIT_ASSERTION_EQUAL( q2, q3 );
	}
Example #29
0
	void Inner_001( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( 1, 2, 3, 4 );
		value_type s = q1.inner( q2 );

		CPPUNIT_ASSERTION_EQUAL( s, value_type( 30 ) );
	}
Example #30
0
	void Op_Multiply_002( )
	{
		quaternion_type q1( 1, 2, 3, 4 );
		quaternion_type q2( 2, 4, 6, 8 );
		quaternion_type q3 = 2 * q1;

		CPPUNIT_ASSERTION_EQUAL( q2, q3 );
	}